Morocco, Africa's top team in the world rankings, came into this tournament feeling like they had a date with destiny.
For more than a decade, King Mohammed VI has poured huge sums of money into the game, using it as a tool for societal and cultural change, a move which resulted in the Atlas Lions becoming the first African nation to reach a World Cup semi-final at Qatar 2022.
But this Afcon was supposed to be their crowing achievement, the moment to end a long trophy drought stretching back to 1976.
Instead, they become just the fourth hosts to lose in a final - having seen the past 12 who have reach the showpiece end up as champions.
The moment which broke their hearts came from Villarreal man Gueye, a towering midfield presence who has been one of the tournament's standout players.
Having burst forward from just inside the Moroccan half, he shrugged off a tired-looking challenge from Hakimi just outside the box and smashed a left-foot rocket into the top right-hand corner, clipping the underside of the bar as it went in.
Morocco did their best to fight back, with substitute Youssef En-Nesyri stooping to head just wide at the near post 10 minutes after Gueye's goal and Aguerd's header off the bar following in the second half of extra time.
But Senegal also had chances to extend their lead, with Paris St-Germain teenager Ibrahim Mbaye's slaloming run and shot blocked by a lunging Hakimi and Cherif Ndiaye denied by a brilliant double save from Bounou.
At the other end, Mendy was being bombarded with missiles thrown by fans behind his goal, with one invader making it onto the pitch next to the former Chelsea stopper before security managed to force him away.
The recriminations over the way in which this game ended will go on for some time - but Senegal are unlikely to care.
If this is to be Mane's final Afcon he has bowed out in style, and the sight of him being hoisted on to the shoulders of his team-mates, trophy in hand and having had the captain's armband thrust upon him, will hopefully last longer.