African kingdoms and tribes went to war with each other, just like anywhere else, and sometimes the winners would capture prisoners to sell into slavery, as the “spoils of war”.
The Europeans came to African port cities looking to sell guns and buy gold and spices and cloth. Some of these cities had slave markets. The Europeans who had just founded colonies in the Americas had a desperate need for *labor* to work the sugar plantations they’d set up there. It was nearly impossible to get Europeans to come work those plantations voluntarily, as the conditions were so miserable, so the only way to get labor was to buy slaves.
The Europeans bought all the slaves they could get their hands on. It spurred the African kingdoms to go to war *more* so they could capture even more slaves and make even more money selling the slaves to the Europeans.
That’s how it worked for 300-400 years, from the late 1400s to the 1800s. The Europeans didn’t *conquer* sub-Saharan Africa for most of that period. The Portuguese captured a few port cities around the continent, and the Dutch conquered some bits of South Africa and settled there. But for the most part Africa remained independent. It was only in the mid-to-late 1800s that two technological inventions allowed Europe to completely dominate Africa. The drug *quinine* was discovered to be a cure for malaria, which used to kill nearly every European soldier sent to Africa. And then the *Gatling gun* gave European empires a huge military advantage that the Africans couldn’t beat. So by the 1890s all of Africa was colonized by European empires, except for Ethiopia.
Latest Answers