Senegal's Sadio Mane had a penalty saved but later scored his first two goals at this year's Africa Cup of Nations as they beat Kenya 3-0 to reach the round of 16 on Monday.
Mane's spot kick was stopped by Patrick Matasi in the first half and it looked to be a costly miss as Senegal struggled to break down a resilient Kenyan side who could still qualify.
But it all changed after Ismaila Sarr broke the deadlock in the 63rd minute and Mane then added two more, the second of his brace also from a penalty which this time he buried confidently.
Senegal, who finished second in Group C with six points behind Algeria on nine, will face Uganda in the knockout round on Friday, while Kenya, who have three points, must wait to see if they progress as one of the best third-placed teams.
Senegal coach Aliou Cisse had been reluctant to allow Mane to take the second penalty but said it was the correct decision.
"He was right, it's important that he takes that responsibility, and it's important that he gets that confidence," Cisse told reporters.
There was plenty of drama in the first half and Senegal claimed they should have been awarded a penalty when Victor Wanyama appeared to handle following a corner, but Egyptian referee Ghead Grisha emphatically waved play on.
Shortly afterwards, Kenya's Musa Mohammed clumsily tripped Saliou Ciss and this time there was no let-off for the Harambee Stars as the official pointed to the spot.
However, Matasi, who plays his club football in Ethiopia, dived to his right to save Liverpool forward Mane's spot kick.
Matasi also saved a shot from Henri Saivet just before the penalty and tipped Sarr's effort onto the bar on the stroke of halftime to keep Kenya's goal intact.
But the keeper was at fault when the defence was finally breached in the 63rd minute as he failed to intercept a cross and Sarr hooked the ball in. After that it was easy for Senegal.
Nine minutes later, they cleared a corner and broke down field, Mane was released and drilled the ball past Matasi.
By now Kenya looked ragged and Philemon Otieno showed their desperation as he tripped Sarr, conceded a penalty and was sent off. Mane stepped up and made no mistake second time around.
"We were not so far, but not so close. If you commit a mistake, you are punished immediately when you play Senegal," said Kenya coach Sebastien Migne.
"For one hour, we created some problems, some difficulties at least. Now, we need to wait and we expect and hope for some help. We will learn... we have learned a lot, I think."