The victory, the biggest by any team in the tournament so far, means Malawi finish as runners-up in the pool behind Zambia, who kept up their perfect record with a 3-0 victory over Madagascar.
Defending champions Zambia top the pool with three wins from three and 10 goals scored. They have yet to concede in the tournament to date. They will now play the second-placed team in Group A in the Last 4, which will be decided on Wednesday.
Malawi went into their match with Kenya knowing a draw would be good enough to seal a semifinal spot, but went on the attack from the off.
Peter Banda grabbed a hat-trick, as well as the Man of the Match award, as he gave the Kenyan defence a torrid time. Malawi’s other goals came via Frank Chizuze, who opened the scoring on 19 minutes, and Francisco Madinga.
Banda is now joint top-scorer in the competition along with Zambia’s Nicholas Mulilo, who was rested for their clash with Madagascar.
Instead it was George Nyimbili who did the damage for the Young Chipolopolo with a brace after Mwiza Siwale had opened the scoring.
Malawi must also await their semifinal opponents as Group A comes to a head on Wednesday.
South Africa need just a point against hosts Mauritius to top the pool, but defeat by a heavy margin could see them eliminated if Namibia also beat Seychelles.
That would leave South Africa, Mauritius and Namibia all on six points in the pool and with an even head-to-head record, meaning it would go down to who has the best record in matches between the sides.
South Africa have the advantage of goal-difference but depending on the results could yet be caught.
Tuesday’s Group B results:
Malawi 5 (Chizuze 19’, P.Banda 5’, 59’, 89’, Madinga 64) Kenya 0
Madagascar 0 Zambia 3 (Siwale 19’, Nyimbili 39’, 88’)
Wednesday Group A fixtures:
South Africa vs Mauritius (KO 3pm local; 11am GMT)
Seychelles vs Namibia (KO 3pm local; 11am GMT)