Gräfenstein Castle (German: Burg Gräfenstein) is a ruined rock castle about 2 kilometres (1.2 mi) east of the village of Merzalben in the German state of  Rhineland-Palatinate. It is in the county of Südwestpfalz within the Palatine Forest and is often called Merzalber Schloss ("Merzalben Castle"). It is built on a rock plateau 12 metres (39 ft) high at an elevation of 447 metres (1,467 ft) above sea level.
 Gräfenstein Castle was built by the Saarbrücken counts, who had lost their fortress and were in need of a new one. Evidence for the exact date of the castle's building does not exist although the earliest record dates to a 1237 deed of partition by the counts of Leiningen. But from the castle's design and materials it can be deduced that it was built sometime between 1150 and 1200. Another clue is in the date of the restoration of the stone fortress, which took place in 1168, and coincides with first construction work on Gräfenstein Castle. The central element of the site, with its bergfried and palas probably dates to the 12th century and thus goes back to the Hohenstaufen era. The upper part of the castle was built on a rock shelf 12 metres high. The building's highlight is the peculiar seven-sided tower.
 Possession of Gräfenstein was first given to the younger counts of the von Leiningen family. The House of Leiningen was related to the von Saarbrücken counts. The castle was built primarily for protection. It lies on the intersection of the Diocese of Worms, Speyer and Metz. The boundaries of these places were contiguous with that of Gräfenstein's, so the castle's main function was to maintain a hold on the uncertain borders. So was the protection of the surrounding forests and villages.
 In 1317 the castle went into the possession of the collateral Leiningen-Dagsburg line. By 1367 they had to sell 7/8 of the estate to Prince Elector, Rupert I of the Palatinate. Through marriage, Gräfenstein went in 1421 to the Counts of Leiningen-Hardenburg. They had the castle expanded, particularly the lower ward.
 The castle was first destroyed in 1525 during the German Peasants' War. Rebuilding work began in 1535 and, in 1540, the castle was sold by its owner, Count Palatine Johann von Simmern to the Count Palatine, Rupert, who used it from then on as his new residence and also introduced the Reformation locally. Rupert had been born in 1506 in Zweibrücken and died at Gräfenstein Castle on 28 July 1544.
 Thereafter the castle continued to change hands, until in 1570 it was transferred, together with its associated villages, to Badenese ownership (Margraviate of Baden-Baden and Baden-Durlach). In 1635, during the Thirty Years' War, the castle was razed by fire (due to "carelessness on the part of the imperial forces...") and became unusable for a long time. In 1771, when the rule of the Counts of Baden-Baden ended, ownership of the castle passed into the hands of the government of Baden-Durlach. They held the castle until the French Revolution. The castle had at this point reached the crest of its glory, and after that it fell into dereliction.
 In spite of that the fortification is relatively well preserved. The first conservation measures on the ruins were carried out in 1909/10 and 1936/37. And from 1978 to 1986 the state of Rhineland-Palatinate had the ruins comprehensively restored at some cost.
 Gräfenstein is one of the most important, Hohenstaufen era castles in Rhineland-Palatinate. It is about 80 metres (260 ft) long and about 60 metres (200 ft) wide.
 Gräfenstein is the only castle in Germany with a heptagonal keep or bergfried. This may still be climbed today up a narrow spiral staircase. The shape of the tower is based on a combination of an octagon (c.f. Steinsberg) and a triangle. Whilst on a pentagonal tower, a triangular point is added to the rectangular main body on the side facing the enemy, in the case of Gräfenstein two shoulders of the octagon have been extended into a point. Another feature is the fact that the bergfried at Gräfenstein is not oriented in the direction of an attack, because the castle stands on a conical hill with steep drops on all sides. This underscores the symbolism of military architecture, which was on an equal footing with functionality in the High Middle Ages. The ground-level entrance was not added until more recent times.
 Around the bergfried there is a mantlet wall, which appears to represent five sides of a slightly irregular octagon, due to the nature of the terrain. The outer wall of the upper ward consists externally entirely of rusticated ashlars. Access was via a wooden staircase at the site of the present stone one. The gate at this point has not survived. In the northern part of the upper ward lies the Hohenstaufen era palas, whose walls have been preserved as far as the height of the rain gutters. Its plan resembles a pointed triangle. Its windows were replaced in the Late Middle Ages, but the Romanesque window arches in the upper storey can still be made out.
 The most important late medieval additions to the upper ward are the  toilet tower and a staircase tower dating to the 16th century. There were no other structural changes in the palas.
 The lower ward, which is laid out in a ring around the foot of the rock on which the upper ward is built, goes back to Hohenstaufen times, at least in its southern and western sections. The shape of the irregular polygon is again repeated on the expected direction of attack, so that there is a triple defence here consisting of enceinte, mantlet wall and bergfried. Thus the southern part of the lower ward was built shortly after the upper ward at the end of the 13th century. The northern part with its zwinger may not have been added until the 15th century.
 Two small round towers with loopholes for hand weapons guarded the approach on the northeastern side of the lower ward. In the entrance, original stone slabs with cartwheel grooves may still be seen. Two storey buildings were erected against the inside of the curtain wall on the southern side of the lower ward. Four chimneys and six garderobes from these buildings can still be seen. They indicate the presence of a large castle garrison.