In 1187 Sultan Saladin, founder of the Ayyubid dynasty, defeated the Crusaders in the Battle of Hattin and subsequently captured Jerusalem and almost all of Palestine.