Europeans have been involved in Africa since the 16th century, when the Portuguese used their cannons to take control of cities on coast to set up their trading post empire, but in the second half of the 19th century, Europe suddenly and spectacularly succeeded at colonizing basically all of Africa. Why?
Well, the biggest reason that Europeans were able to extend their grasp over so much of the world was the same reason they wanted to do so in the first place: industrialization. Nationalism played its part, of course. European states saw it as a real bonus to be able say that they had colonies--so much so, that a children's rhyme in An ABC for Baby Patriots went, "C is for colonies. Rightly we boast. That of all great countries Great Britain has the most."
But it was mostly, not to get all Marxist on you or anything, about controlling the means of production. Europeans wanted colonies to secure sources of raw materials, especially cotton, copper, iron, and rubber, that were used to fuel their growing industrial economies.
And in addition to providing the motive for imperialism, European industrialization also provided the means. Europeans didn't fail to take over territory in Africa until the late 19th century because they didn't want to; they failed because they couldn't. This was mostly due to disease.
Unlike in the Americas, Africans weren't devastated by diseases like smallpox because they'd had smallpox for centuries and were just as immune to it as Europeans were. Not only that, but Africa had diseases of its own, including yellow fever, malaria, and sleeping sickness, all of which killed Europeans in staggering numbers.
Also, nagana was a disease endemic to Africa that killed horses, which made it difficult for Europeans to take advantage of African grasslands, and also difficult for them to get inland, because their horses would die as they tried to carry stuff.
Also, while in the 16th century Europeans did have guns, they were pretty useless, especially without horses. So most fighting was done the old-fashioned way, with swords. That worked pretty well in the Americas, unless you were the Incas or the Aztecs, but it didn't work in Africa, because the Africans also had swords. And spears, and axes. 
So as much as they might have wanted to colonize Africa in the 16th, 17th, and 18th centuries, Africa's mosquitoes, microbes, and people were too much for them.