It was probably an ancient fortress, but earliest existing defences were built in 1062 by the local Muslim lords, who continued to hold it within the Christian Principality of Antioch in the aftermath of the First Crusade. When the Principality was defeated at the Battle of Harran in 1104, the Byzantine Empire took advantage of the Moslems’ weakness and captured Margat from them. A few years later it was captured by Tancred, Prince of Galilee, regent of Antioch, and incorporated into the Principality.
In the 1170s it was controlled by Reynald II Mazoir of Antioch as a vassal of the Count of Tripoli; the fortress was so large that it had its own household officials and a number of rear-vassals.
Mazoir’s son Bertrand sold it to the Hospitallers in 1186 as it was too expensive for the Mazoir family to maintain. After some rebuilding and expansion by the Hospitallers, it became their headquarters in Syria. Under Hospitaller control, its fourteen towers were thought to be impregnable.
Saladin besieged the castle in 1188 but was unable to capture it and it was one of the few remaining territories left in Christian hands after Saladin's conquests.
By the beginning of the 13th century the Hospitallers controlled the surrounding land and roads and made a large profit from travellers and pilgrims passing through.
Isaac Comnenus of Cyprus was imprisoned there after Richard I of England captured Cyprus from him during the Third Crusade.
The bishop of nearby Valenia also used Margat as his headquarters after around 1240. Margat was second in size in power only to the other Hospitaller fortress to the south, Krak des Chevaliers.
The Mamluk sultan of Egypt Qalawun besieged it beginning on April 25, 1285, and captured it after a month when sappers had undermined the north wall. Qalawun respected the size of the fortress and the courage of its defenders, and allowed the Hospitallers to leave with everything they could carry. Rather than destroy it as he did with other fortresses, he placed a Mamluk garrison in it.