In Morocco, the Arab scholars petitioned to have him released from jail. He was released a year after his arrival on 9 May 1596. Major Dubois, a French author, narrates that: "All the believers were greatly pleased with his release, and he was conducted in triumph from his prison to the principal mosque of Marrakech. A great many of the learned men urged him to open a course of instruction. His first thought was to refuse, but overcome by their persistence he accepted a post in the Mosque of the Kerifs and taught rhetoric, law, and theology. An extraordinary number of pupils attended his lectures, and questions of the gravest importance were submitted to him by the magristracy, his decision always being treated as final."
Despite this adulation, Baba was careful to credit his learning to the Almighty and thus maintained his modesty. A Moroccan source tells of an audience he obtained with Al Mansur. It appears that the scholar gave the sultan something of a dressing down. Baba complained about the sultan's lack of manners, his ill treatment received during his original arrest, the sacking of his private library of 1600 books, and the destruction of the Songhai Empire. We are told by the Moroccan author that Al Mansur "being unable to reply to [any of] this, put an end to the audience."
The professor was detained in Morocco for a total of 12 years. Eventually he received permission from Al Mansur's successor to return to Songhai. Just before his departure across the desert, he vowed in the presence of the leading scholars of Marrakesh who had gathered to give him a send off, "May God never bring me back to this meeting, nor make me return to this country!" He returned to a devastated Timbuktu and died there in 1627. Today the only public library in Timbuktu, the Ahmed Baba Institute (which stores over 18,000 manuscripts) is named in his honor.
Hunwick, J.O. (1964), “A New Source for the Biography of Ahmad Baba al-Tinbukti (1556-1627)”, Bulletin of the School of Oriental and African Studies, University of London 27: 568–593.
Below is also how little the Encyclopaedia Britannica wrote about the famous Prof Ahmad Baba of Songhai:
A descendant of a line of jurists, Aḥmad Bābā was educated in Islāmic culture, including jurisprudence. When Timbuktu was conquered by the Sultan of Morocco in 1591, he was accused of refusing to recognize the Sultan’s authority and of plotting a rebellion. In 1594 he was deported to the Moroccan capital of Marrakūsh. The conditions of his captivity were liberal, and he was allowed to teach and practice law. His fatwās (legal opinions) dating from this period are noted for their clarity of thought and clear exposition of Islāmic judicial principles. He also compiled a biographical dictionary of the famous Mālikī (one of the four schools of Islāmic law) jurists; this work is still an important source of information concerning the lives of Mālikite jurists and Moroccan religious personalities.
When the Sultan of Morocco died in 1603, Aḥmad Bābā was allowed to return to his native city. He spent the last years of his life in scholarly pursuits, which included writing a treatise on the populations of the western Sudan and a grammar of Arabic that is still used in northern Nigeria.