As the final whistle got nearer, substitute Vincent Aboubakar controlled the ball just outside the area, clipped it over a defender, and then shot past the goalkeeper to clinch Cameroon's fifth African title and first since 2002.
Egypt's 44-year-old 'keeper, Essam el-Hadary, watched the tournament-winning shot slide past him right at the end to deny the Egyptians a record-extending eighth title, and el-Hadary a fifth triumph an incredible 19 years after his first.
"I cannot describe it. I know it was a wonderful goal. It was a great goal. It was the goal that gave us victory," said Cameroon striker Robert Tambe, the player who was taken off to make way for Aboubakar. "We feel so much joy. We say thanks to Aboubakar."
Egypt led through Mohamed el-Neny's goal in the 22nd minute but Cameroon's substitutes came to the rescue at Stade de l'Amitie as defender Nicolas Nkoulou, off the bench early after an injury to Adolphe Teikeu, equalized with a header in the 60th minute.
Aboubakar, the halftime super sub, completed the rally. Cameroon, already chosen to host the next Cup of Nations, will be defending champion for the 2019 tournament.
Aboubakar's celebration saw him sprint across the field toward the VIP section, in the process flattening a member of the Cameroon coaching staff who raced out to try and hug him. The big striker was determined to get close to the VIP area to deliver a message. As he approached the enclosure, he stretched out both his arms and pointed to where Cameroon great Samuel Eto'o, one of the African Cup winners in 2002, stood celebrating the goal as a spectator.
The message was: We are back. We are champions again. We've done what you did.
The final in Libreville was rich in African Cup history, although neither team was tipped to get to the title-deciding game at the end of the three-week tournament in Gabon.
Egypt is the record seven-time champion but had qualified for the first time since winning a third straight crown in 2010. With political turmoil at home, Egypt's team suffered badly and couldn't even qualify for the final tournament in 2012, 2013 and two years ago.
Cameroon, with four titles, was one of two teams with the next-best record after Egypt. But Cameroon hadn't won a game at its last three major tournaments and came to Gabon without a bunch of its big-name players from the European leagues. They decided to turn down selection for the squad, perhaps fearing that Cameroon would fail again.
Flemish coach Hugo Broos rebuilt the team with youngsters, took 14 players that had never been to a big event before to Gabon, and focused on team spirit.
It clearly worked. Cameroon entered the stadium ahead of the final with players singing and dancing together. They exited in the same way, this time taking the trophy with them.
On their way to the title, Cameroon's youngsters beat Senegal in the quarterfinals and Ghana in the semifinals, both of them among the pre-tournament favorites.
Against Egypt, Cameroon also faced a formidable challenge after falling behind to el-Neny's sweetly struck shot from a tight angle. Cameroon needed to score two goals in the last 30 minutes to win, more than Egypt's powerful defense had conceded in the entire tournament before the final.
Cameroon did it
"Yes it shows the character, but that I knew from the beginning," Broos said. "I said a few times, I do not have 23 players, I have 23 friends. It's really unbelievable ... I think this is the reason why we won."
When defender Nkoulou powered in his header to equalize, he lay on the ground celebrating and just about every one of his teammates piled on top of him. The game appeared set for extra time, but Aboubakar collected possession in the final moments, looked up and decided to go by himself. He breezed past Egypt's last line of defense to take Cameroon back to the summit of African soccer.
The victors are Cameroon's new generation, but they also made sure to recognize history.
Along with the nod to Eto'o, there was a far more poignant tribute.
The players all put on shirts with No. 17 on the back after the game. It was a reference to the year, they said, but also a tribute to Marc-Vivien Foe, the popular Cameroon player and two-time African champion who collapsed on a field in France in 2003 while playing for his country and died.
No. 17 was Foe's number. It was worn at this tournament by midfielder Arnaud Djoum.
"You win big tournaments as a group, not as individuals," Djoum said. "It was our togetherness."