Benin have delivered one of the biggest upsets in Africa Cup of Nations history, eliminating much-fancied Morocco on penalties after Hakim Ziyech missed a late spot-kick in Cairo.

The Squirrels prevailed 4-1 in the shootout after Sofiane Boufal sent his penalty over the bar, and Benin keeper Saturnin Allagbé tipped Youssef En-Nesyri’s effort onto the woodwork. Midfielder Mama Séïbou then stepped up to score the decisive spot-kick.

The west African side took the lead after 53 minutes through defender Moise Adilehou, but their hopes of a shock victory were dented when En-Nesyri levelled after 76 minutes. Mbark Boussoufa pounced on a defensive error and teed up the Leganés forward to slot home.

Morocco were then awarded a penalty in stoppage time after Stéphane Sessègnon had brought down Achraf Hakimi. Ajax’s Ziyech stepped up and sent Allagbé the wrong way – but his effort struck the post.

In extra time, Benin defender Khaled Adenon earned a second yellow card for dissent but the underdogs held on for penalties. They scored all four of their spot-kicks to reach the last eight for the first time, despite four consecutive draws so far in the competition.

They will face Senegal in the quarter-finals after Sadio Mané scored the only goal against Uganda, but also missed a second-half penalty at the Cairo International stadium.

Sadio Mané celebrates after scoring the winner for Senegal against Uganda. Photograph: Khaled Elfiqi/EPA

The Liverpool forward broke the deadlock in the 15th minute, finishing off a quickfire move after Senegal pounced on a mistake by Godfrey Walusimbi. Uganda rallied impressively from that early setback, with Emmanuel Okwi forcing a save from Alfred Gomis with a shot on the turn seven minutes later.

Uganda goalkeeper Denis Onyango had his teammates’ nerves on edge throughout, charging off his line in the fourth minute and bringing down Ïsmaila Sarr with a wild lunge, earning a yellow card. Onyango was caught out by Sarr again midway through the first half, but made a last-ditch tackle to deny the Senegal winger.

After a scrappy start to the second half, Onyango again charged off his line and this time flattened Mané, conceding a penalty but not picking up a second booking. The goalkeeper made amends by saving Mané’s spot kick to keep his team in the game – although Senegal will feel he should not have still been on the pitch.

Allan Kateregga came closest for the Cranes, curling a free kick over the Senegal wall, but Gomis made another good save and Uganda’s dream run was over. Saturday’s matches see Nigeria take on Cameroon, while hosts Egypt face South Africa.