Most of what is known about his life is gathered from autobiographical notes in his own work. Leo Africanus was born as al-Hasan, son of Muhammad in Granada around the year 1494. The year of birth was estimated from his self-reported age at the time of various historical events. His family moved to Fez soon after his birth. In Fez he studied at the University of al-Qarawiyyin (also spelled al-Karaouine). As a young man he accompanied an uncle on a diplomatic mission, reaching as far as the city of Timbuktu (c. 1510), then part of the Songhai Empire. In 1517 when returning from a diplomatic mission to Constantinople on behalf of the Sultan of Fez Muhammad II he found himself in the port of Rosetta during the Ottoman conquest of Egypt. He continued with his journey through Cairo and Aswan and across the Red Sea to Arabia, where he probably performed a pilgrimage to Mecca.
On his way back to Tunis in 1518 he was captured by Spanish corsairs either near the island of Djerba or more probably near Crete. He was taken to Rome and initially imprisoned in Rhodes, the headquarters of the Knights Hospitaller. During this period, the usual fate of unransommed Muslim captives was slavery in Christian galleys, but when his captors realized his intelligence and importance, he was moved to Castel Sant’Angelo in Rome and was later presented to Pope Leo X. He was soon freed and given pension to persuade him to stay. He was baptized in the Basilica of Saint Peter's in 1520. He took the Latin name Johannes Leo de Medicis (Giovanni Leone in Italian). In Arabic, he preferred to translate this name as Yuhanna al-Asad al-Gharnati (literally means John the Lion of Granada). It is likely that Leo Africanus was welcomed to the papal court as the Pope feared that Turkish forces might invade Sicily and southern Italy, and a willing collaborator could provide useful information on North Africa.
Leo Africanus left Rome and spent the next three or four years traveling in Italy. The death of his patron Leo X in 1521, and suspicions from the new Pope Adrian VI against a Moor in court, was likely the reason for his leaving Rome. While staying in Bologna he wrote an Arabic-Hebrew-Latin medical vocabulary, of which only the Arabic part has survived, and a grammar of Arabic of which only an eight-page fragment has survived. He returned to Rome in 1526 under the protection of the new Pope Clement VII, a cousin of Leo X who replaced Adrian. According to Leo, he completed his manuscript on African geography in the same year. The work was published in Italian with the title Della descrittione dell’Africa et delle cose notabili che iui sono, per Giovan Lioni Africano in 1550 by the Venetian publisher Giovanni Battista Ramusio. The book proved to be extremely popular and was reprinted five times. It was also translated into other languages. French and Latin editions were published in 1556 while an English version was published in 1600 with the title A Geographical Historie of Africa. The Latin edition, which contained many errors and mistranslations, was used as the source for the English translation.
There are several theories of his later life, and none of them are certain. According to one theory, he spent it in Rome until he died around 1550, the year Description of Africa was published. This theory was based on indirect allusion in a later preface to this book. According to another theory, he left shortly before the Sack of Rome by Charles V's troops in 1527. He then returned to North Africa and lived in Tunis until his death, some time after 1550. This was based on records by German orientalist Johann Albrecht Widmannstetter, who arrived in Italy and planned (but ultimately failed) to travel to Tunis to meet Leo who had since reconverted to Islam. Yet another theory said that he left Tunis after it was captured by Charles V in 1535 for Morocco, his second home country after Granada where his relatives were still living. This was based on the assumption that Leo, having left Granada, would not have wanted to live under Christian Spanish rule again, and his wish (recorded in Description of Africa) that he wanted to ultimately return to his home country "by God's assistance".
It is unlikely that Leo Africanus visited all the places that he describes and he must therefore have relied on information obtained from other travellers. In particular, it is doubtful whether he ever visited Hausaland and Bornu and it is even possible that he never crossed the Sahara but relied on information from other travellers that he met in Morocco. The historian Pekka Masonen has argued that the belief of his further travels was based on misreadings by modern scholars who interpreted his book as an itinerary.