Among the Turkish slave officers in Baghdad and Samarra was a Uyghur named Tulun, whose son Ahmad received a good Islamic education and became a protégé of one of the top Turkish generals. Of course he joined the army, where he served with distinction. In 868, the Turkish general was given the oversight (and tax revenues) of Egypt, so he sent Ahmad ibn Tulun to be the governor while he himself remained in Samarra.
These were years of great instability, and in Egypt as well. Ibn Tulun spent four years struggling to remove rivals who wanted to grant him partial control, while they kept a hand on the revenue. A number of revolts, purportedly led by descendants of Ali, had to be fought down, and at one point, the Caliph requested Ibn Tulun to march into Syria and conquer a spin-off Bedouin rebel state. To make that happen, Ibn Tulun purchased 40,000 African and “Roman” (Greek, Slavic, etc) slaves to train as soldiers. With his original Turkish corps of 20,000+, he now had a very large army. He also kept a personal bodyguard of Afghanis.
Where to house all of these soldiers? The original Medinat al-Fustat had been expanded with an Umayyad-era al-Askari (“ask” means soldier), but to find more housing, he built a new al-Qata’i (Quarters) to the north. Each unit received a plot of land to build their barracks and houses, and he also planned civic things like a race track and a hospital. Most famously, he also built there a mosque. (Personally, he enjoyed living in a nearby Christian monastery.)
The mosque was designed in a specific style that imitated Samarra, but its architect was a Christian. I couldn’t find much on him, and his name sounded Arabic, but he also designed a still-functioning Nilometer so he must have been a native Egyptian. This is the Nilometer on the Island of Roda in Cairo, built in 861. Measuring the Nile—and all things measurement—remained a native Egyptian/Coptic specialty for a long time after the Arab conquest.
Ibn Tulun followed the old plan of building the mosque right next to his palace, with a door that permitted him to enter without going into the street. The mosque was huge, with four domed halls around the open courtyard; under one of the domes there was a huge marble fountain. The minaret was built with an external spiral staircase leading to the top, like one in the new/current capital of Samarra. The palace was torn down by the following century, when the Fatimids rebuilt everything, but they preserved the mosque.
At a time when the Caliphs in Samarra were unable to pay their troops, where did Ibn Tulun get all this cash? These were good years for Nile floods, so agricultural revenues were high. In the south (Upper Egypt), they had discovered gold and emerald mines. Gold and gem mines always bring a rush of immigrants; in this case they were Arabic-speaking newcomers who contributed to the ongoing Arabization of Egypt.
By this time, Egyptians who spoke Coptic at home had learned Arabic at school and work, and in the cities some stopped speaking Coptic altogether. In spite of this Arabization, Ibn Tulun was good to religious minorities, especially the Christians. Churches and synagogues could be rebuilt, and persecution stopped. We see this cycle a lot in Egyptian history: the religious minorities are typically needed by a government whose power is new, whereas in a later stage, the same government may not need their support and use them as scapegoats. Ibn Tulun wanted, and received, their support.
Back in Samarra, Caliph Mu’tamid’s brother usurped much of his power. The brother lived in Baghdad, running day to day affairs as commander of the army, and he wanted equal or greater shares of tax revenue to be directed to him, not to the Caliph in Samarra. Ibn Tulun resisted this directive, and when the brother required an oath of allegiance to himself as Regent, ibn Tulun refused. The Caliph’s brother withdrew ibn Tulun’s appointment, and of course ibn Tulun didn’t obey but prepared for war. He built new fortresses and his own fleet of warships. It worked; the Abbasid general sent to suppress him backed off.
Now ibn Tulun had all the apparatus of independent governing. He decided to deal with disarray in Syria by leading his army north and taking it over. He stayed on in Syria for a year, solidifying his control. When he came home, he began minting coins in his own name, though with the legitimate Caliph’s name included.
Ibn Tulun died of illness in 882. His second son inherited great wealth and became Emir after him. Sensing an opportunity, Baghdad’s forces tried to take back Syria, but they failed. Ibn Tulun’s son even extended his authority into Iraq. His successes forced the Abbasids to negotiate with him, and in 886, al-Muwaffaq recognized Egypt as independent.
In 892, ibn Tulun’s granddaughter married the Abbasid Caliph Mu’tadid. Her dowry was a million dinars, a very high price to pay for the honor. Would ibn Tulun himself have paid so much for an honor that might not do his family much good in the end? He was probably too practical and strategic. But ibn Tulun’s younger sons and grandsons were not effective rulers. They were mostly controlled by their huge African and Turkish slave armies. The nascent dynasty faltered and its power shrank. In 905, only about twenty years after ibn Tulun’s death, an Abbasid general conquered the last Tulunid and brought Egypt back into the Abbasid fold.