Martinsburg Castle was built at the end of the 13th century as a base for exercising the customs rights of Mainz. Since 1292, the Elector and Archbishopric of Mainz had secured shares in the Boppard imperial customs with the permission of King Adolf of Nassau. Since the Electorate of Mainz's Lahneck Castle rose on a hill some distance from the Rhine, a permanent building was erected directly on the Rhine to secure the collection of the Rhine customs. Probably in the middle of the 13th century there was already a fortified building at this place for the supervision of the navigation, which was mentioned in a document in 1244. The oldest parts of the castle are a rectangular residential tower with two corner towers and the foundations of the hexagonal main tower in the south of the complex. The 28-meter-high keep, which rises in this place today, was built around 1400 and has an adjoining staircase and abort tower. In connection with the construction of the city wall of Oberlahnstein after 1324, the Martinsburg was also extended. It formed the southwestern corner of the town fortification. Towards the town, the lowland castle was secured with a moat and a fixed gate, on which a cast-iron bay window is still visible today. From such parts protruding above the castle gate, attackers could be doused with hot pitch or oil. The fortification towards the city was necessary because it could be conquered by enemies and the castle then remained the last place of refuge for the officials of Mainz. But also an uprising of the city population against their episcopal-court lords was not necessarily impossible. As the town castle of the economically up-and-coming Oberlahnstein, it housed the customs clerk and customs personnel, gatekeepers and tower guards, as well as other auxiliary personnel. The moated castle was never destroyed, but it was altered by additions and conversions until the end of its affiliation with the Electorate of Mainz in 1803. Thus, the northwest wing was added as early as the 14th century, followed by today's southeast wing in 1497. From 1719 to 1721, the gap between the medieval residential tower and the keep, which still existed on the Rhine side, was closed by a three-story central building in the Baroque style. As an occasional secondary residence of the electors of Mainz, Martinsburg Castle was able to leave Lahneck Castle far behind in importance since the end of the Middle Ages.