The tournament had been waiting for Riyad Mahrez and in the semi-final he finally arrived. It came down in the end to one shot. A free-kick, perhaps 20 yards out: score it and Algeria were through to their first Cup of Nations final since 1990; miss and they faced extra-time against a Nigeria team who had been improving as the game went on and, at that point, were looking fitter and stronger than their opponents.

It was not that Mahrez has played badly. He has scored two goals and functioned efficiently in a technically gifted forward line. It was just that he had not had a match in which he had played an obviously decisive role.

Dylan Bronn own goal sends Senegal through to Africa Cup of Nations final Read more

This, though, was his chance to be a hero – and he seized it. The strike was perfect, whipped left-footed round the wall and beyond the dive of Daniel Akpeyi. It was the last kick of the game, “a wonderful free-kick from a genius player” as the Nigeria coach, Gernot Rohr, put it.

Algeria had won and will face a Senegal side without the suspended Kalidou Koulibaly in the final. That, though, is only a small part of the story, much of which revolves round Algeria’s strange reluctance to believe in themselves and take advantage of their superiority.

Here they had been much the better side in the first half, taking the lead through William Troost-Ekong’s 40th-minute own goal. But, as is their way, they then retreated and, rather than looking to press home their advantage, they sat back and spoiled. “We were too deep,” the Algeria coach, Djamel Belmadi, said. “There was not enough pressure on the opponents, due maybe to the fatigue of the players.”

Facebook Twitter Pinterest Algeria’s Djamel Benlamri and Aissa Mandi celebrate after William Troost-Ekong’s own goal. Photograph: Sumaya Hisham/Reuters

Still Nigeria had essentially been devoid of threat in the first half of the second half, struggling to get their wingers, so influential in the quarter-final against South Africa, into the game, when Oghenekaro Etebo’s speculative shot struck the arm of Aissa Mandi. Play carried on for well over a minute before there was finally a break and, to widespread bewilderment, a VAR review. The replay, though, was clear enough: under the modern interpretation it was a penalty. Odion Ighalo converted and suddenly everything changed: the tone of the game and the mood in the stadium.

Initially it had all seemed calm. To one side were the Nigerians, two vast brass bands in green and white, one perhaps 1500 strong, the other around 500. To the other were the Algerians, 10,000 of them with their banners. In between were thousands upon thousands of orange and blue seats and then, in the centre, either side of the press box, a few thousand locals who had bought tickets in the expectation Egypt would be here. The 75,000 capacity Cairo International Stadium was perhaps a fifth full.

The Fiver: sign up and get our daily football email.

Algeria and Egypt have a ferocious rivalry, as the 2009 World Cup play-off between the sides, and then the brutal Cup of Nations semi-final in Benguela a few months later attest. But when Rohr spoke before the game of Egypt as Algeria’s “Arab brothers” he was correctly defining the mood. The Egyptians in the crowd, at first, were clearly backing Algeria, who responded by joining in the chants and raising of lit mobile phones in the 22nd minute in recognition of Mohamed Aboutrika, the great former playmaker who wore 22 when leading Egypt to victory in the Cup of Nations the last time they hosted it, but is now in effect exiled from his homeland after being included on a terrorism watchlist.

But that is where alliances and relationships start to become a little clouded. Three Algerian fans were arrested early in the tournament for carrying signs bearing messages relating to political events back in Algeria, suggesting a level of cooperation between Egyptian and Algerian authorities.

When Ighalo equalised, though, there was an exchange of bottles between the Algerian and Egyptian sections. There was a rush to the fence between them and briefly it seemed something very serious might break out. As it was, everything calmed down quickly as security moved in.

Algeria 2-1 Nigeria: Africa Cup of Nations semi-final – as it happened Read more

On the pitch Algeria came again. Belmadi spoke of their “great attitude and mental strength” but the tactical improvement since he took the job less than a year ago has been remarkable. As Rohr noted, Algeria are better balanced now than when Nigeria beat them in World Cup qualifying and here the plan to close the spaces for the wingers worked perfectly. The only issue was fitness but one last surge brought the winner.

By the end the exchanges between rival fans were of applause. That, hopefully, bodes well for security around the final but there is bound to be some unease on the part of the authorities if, as expected, thousands more Algerians travel east for the game. At least, though, there may be a sense of occasion befitting a final – and there is no doubt that on form and ability Algeria deserve to be there.