After defeating the Mamluks and gaining control of Mecca and Medina in 1517, the Ottoman sultan Selim I adopted the title. It was used by all subsequent sultans until Mehmed VI, the last.
The first Saudi king to assume the title was Fahd bin Abdul Aziz in 1986. King Fahd replaced the term "His Majesty" with "Custodian of the Two Holy Mosques". The reigning king, Abdullah bin Abdul Aziz, has taken the same title after the death of King Fahd, his half brother, in 2005.