Spurred on by a sold-out crowd, Harambee Stars started on a positive note with Ben Stanley Omondi winning a free-kick from outside the box. Boniface Muchiri stepped up to curl a right-footed effort which troubled Madagascar goalkeeper Ramandimbisoa Michel before going out for the first corner of the game.
Kenya continued to attack with the crowd rallying behind them and Omondi should have scored in the 12th minute after being put through by Muchiri but Michel came out of his line to clear the danger.
Kenya almost paid for their missed chances five minutes later when Madagascar almost took the lead. A long ball from the keeper found forward Jean Luc Ranaivoson unmarked but before he could loop the ball past Bryne Omondi, the Harambee Stars custodian came out of his line to hit the ball back to play.
Kenya continued to look the dominant side and in the 23rd minute, they had another great chance to break the deadlock but it went begging.
A super delivery from midfielder Marvin Nabwire, who was red-carded in the group stage game against Angola, found Stanley Omondi unmarked inside the box but his glancing header went inches wide.
Muchiri squandered another chance for Harambee Stars in the 28th minute after his attempted left-footed effort from outside the box hit the legs of a Madagascar defender for a fruitless corner.
Kenya's finishing continued to go wanting as striker Ryan Ogam, the scorer in the 1-1 draw against Angola and 1-0 win against two-time CHAN champions Morocco, missed another clear chance after Lewis Bandi and Alpha Onyango had exchanged passes from a counter-attacking move.
At the start of the second period, Kenya started from where they had left and it took them only one minute to take the lead.
A free-kick from Muchiri found Alphonse Omija, who rose highest to thump in a header past the stretching hands of Michel. A minute after the restart, Kenya thought they had doubled the lead when Ogam bundled in a loose ball from a corner, but his effort was ruled out for a push on a defender by Stanley Omondi in the build-up.
Madagascar levelled the scores from the penalty spot in the 69th minute after Kibwage handled the ball inside the box. Fenohasina Razafimaro stepped up to send Omondi diving the wrong way.
After extra-time, the game went to penalties with Madagascar scoring the first and Mohammed Saraj converting for Kenya. Keeper Omondi saved Madagascar's second after diving the right way before Sakari scored to make it 2-0 for Kenya.
Madagascar scored to make it 2-1. Sylvester Owino scored Kenya's third before Madagascar scored their third. Kibwage then missed Kenya's fourth with a weak effort before Omija decisively hit his effort wide to hand Madagascar the win.
Kenya’s superb campaign in the group stages saw them finish top of Group A with 10 points, while Madagascar finished second in Group B with seven points. Harambee Stars kicked off their CHAN campaign with a 1-0 win against two-time CHAN winners DR Congo, before securing a 1-1 draw against Angola.
Kenya recovered to beat another two-time CHAN champions Morocco 1-0 despite playing with 10 men before rounding off their group matches with a 1-0 win against Zambia. McCarthy’s men conceded only once in four matches, underlining their defensive discipline.
