Short answer
The Abbasid Caliphate in Baghdad fell in 656 AH (1258 CE), when the Mongols under Hulagu sacked the city and killed the caliph al-Musta'sim. A line of Abbasid caliphs with little real power then lived in Cairo under the Mamluks until the Ottomans took Egypt in 923 AH (1517 CE).
Sunni historians such as Ibn Kathir record the fall of Baghdad in 656 AH as one of the greatest disasters of Islamic history. The Abbasid line continued in Cairo as a religious office until 1517.
The four schools agree on this.
Explanation
The Abbasids took power in 132 AH (750 CE) and built Baghdad as their capital. For about two centuries they ruled a vast state and presided over a great age of learning (see Islamic Golden Age). From the tenth century, real power passed to others: the Buyids took control of Baghdad in 334 AH (945 CE), then the Seljuq Turks in 447 AH (1055 CE). The caliph often kept the title while others ruled.
In the 1250s the Mongols advanced west. In 656 AH (1258 CE) Hulagu Khan besieged Baghdad. The city fell, the caliph al-Musta'sim was killed, and a huge number of people died. Historians tell of libraries thrown into the Tigris. Ibn Kathir, writing in the next century, describes it among the worst calamities to befall the Muslims.
The Mamluks of Egypt stopped the Mongols at Ayn Jalut in 658 AH (1260 CE). They brought a member of the Abbasid family to Cairo and made him caliph in 659 AH (1261 CE). These Cairo caliphs gave legitimacy to the Mamluk sultans but held little power. When the Ottomans conquered Egypt in 923 AH (1517 CE), that line came to an end.
Muslims read such events as reminders that power rises and falls by Allah's will. For the difference between the two great dynasties, see Umayyad vs Abbasid caliphate.
The evidence
Quran, Surah Aal-i-Imraan 3:140
إِن يَمْسَسْكُمْ قَرْحٌۭ فَقَدْ مَسَّ ٱلْقَوْمَ قَرْحٌۭ مِّثْلُهُۥ ۚ وَتِلْكَ ٱلْأَيَّامُ نُدَاوِلُهَا بَيْنَ ٱلنَّاسِ وَلِيَعْلَمَ ٱللَّهُ ٱلَّذِينَ ءَامَنُوا۟ وَيَتَّخِذَ مِنكُمْ شُهَدَآءَ ۗ وَٱللَّهُ لَا يُحِبُّ ٱلظَّٰلِمِينَ ﴿١٤٠﴾
If a wound should touch you - there has already touched the [opposing] people a wound similar to it. And these days [of varying conditions] We alternate among the people so that Allah may make evident those who believe and [may] take to Himself from among you martyrs - and Allah does not like the wrongdoers -
Power and fortune pass between peoples by Allah's will.
Where the ruling is recorded
- al-Bidaya wa al-Nihaya (Ibn Kathir), Events of the year 656 AH, the coming of the Tatars to Baghdad. Ibn Kathir's account of the fall of Baghdad.
- Tarikh al-Khulafa (al-Suyuti), Section on al-Musta'sim and the Abbasid caliphs in Egypt. Lists the caliphs before and after 1258.
- al-Muqaddima (Ibn Khaldun), Chapter on the caliphate becoming kingship. Explains how real power left the caliphs.
This answer is pending review by the scholars on our team. Quran translation by Sahih International. Hadith Arabic from the standard editions of the six books and the Muwatta, with gradings as recorded there; the English is our own rendering. Spotted a mistake? Tell us.