Simon Msuva gave Taifa Stars an early lead but Michael Olunga equalised before Mbwana Samatta gave his team a 2-1 half-time advantage.
However, Johanna Omollo and Olunga scored a goal each in the second half.
Coach Sebastien Migne made three changes from the side that lost 2-0 to Algeria, bringing in Johanna Omollo, David Owino and Eric Ouma in place of Eric Johanna, Philemon Otieno and Dennis Odhiambo.
Despite Kenya settling early, it was Tanzania who went ahead in the 6th minute. A good ball from the midfield found Mbwana Samatta on the left and the striker unleashed a fierce shot that Patrick Matasi parried as far as Msuva, and the forward made no mistake from six yards.
Harambee Stars' first shot on target fell to Ouma in the 13th minute when a flicked header found its way to him. However, the former Gor Mahia player's shot was well saved by Aishi Manula.
Kenya came close twice in the 21st minute when Ouma's corner was almost put into the net by keeper Manula, but he was saved by the crossbar. The ball kindly fell to Olunga whose header came off the crossbar and went off for a goal kick.
Coach Migne pulled out Francis Kahata in the 33rd minute and brought in Sofapaka's John Avire as he aimed at getting a goal before the half time whistle.
Matasi was forced into a fine save by Hassan Ramadhan a few moments later from a good free kick about 35 yards from goal. Kenya reacted by initiating a perfect counter-attack and Avire was fouled in the process.
The free kick was delivered and Manula failed to clear it, and it eventually fell to Olunga whose bicycle kick found the back of the net.
Samatta however, gave Taifa Stars a lead in the 40th minute when he stole the ball from the defenders before hitting a low drive into the net to ensure his team went into the break with a deserved advantage.
About five minutes after the break, the Tanzanian defenders failed to clear the ball from the dangerous area, and it fell to Avire who took long to make a decision on what to do with the ball, and it was eventually cleared.
In the 59th minute, Kenya won a corner, and as usual, it was Ouma who played it in. Captain Victor Wanyama headed it on target but the custodian pulled off a stunning save to deny the Tottenham Hotspur midfielder.
Once again, Harambee Stars made it even with half an hour left; Kenya won a corner after quick and short exchanges, Ayub Timbe managed to bring the ball in and Omollo headed it in.
Kenya went in front for the first time in the 81st minute through Olunga. Substitute Johanna, who had replaced Aboud Omar, initiated an attack from the team's half, sprinted and passed the ball to the lanky striker who controlled the ball perfectly before unleashing a strong low drive that Manula failed to save.
Kenya XI: 18. Patrick Matasi, 15. David Owino, 3. Abud Omar, 2. Joseph Okumu, 5. Musa Mohamed, 12. Victor Wanyama, 8. Johanna Omollo, 11. Francis Kahata 7. Ayub Timbe, 13. Eric Ouma, 14. Michael Olunga.
Subs: 1. Faruk Shikalo, 23. John Oyemba, 4. Joash Onyango, 20. Philemon Otieno, 6. Bernard Ochieng, 21. Dennis Odhiambo, 17. Ismael Gonzalez, 10. Eric Johanna, 19. Ovella Ochieng, 16. Paul Were, 9. John Avire, 22. Masud Juma.