According to the carefully conducted research, Bill Gates wasn't even close to the richest person in the history of billionaires. Rather, it was a unexpected figure. He was Mansa Musa from Mali, who was worth $400 billion. He was a Muslim Emperor of West African Mali Empire and reigned between 1312-1337. His wealth came from his country's product of salt and gold that was exported to half of the world at that time. In his lifetime, he built a huge number of mosques and schools in his empire.
He is also famous for his Hajj journey to Makkah that involved over 60,000 people carrying huge amount of gold that he gave away to the poor people in Cairo and Madina. He also expanded the borders of his empire to a great extent. It stretched around 2000 miles.
Towards the end of his reign, his sons followed suit, but could not hold on to the wealth he had accumulated. He ruled for 25 years, and is counted among the most generous kings of the world.
Here's a video by Ted-Ed that further explains about him.