DR Congo and Gabon completed the quarter-final line-up at the African Nations Championship after sealing first and second spots in Group D.
A 2-1 victory for DR Congo over Burundi saw them move up from third to seal the runners-up spot in the table, two points above The Swallows.
Gabon left it very late to book their place as they needed to come from behind to beat Mauritania 4-2.
The win took Gabon to seven points and put them through as group winners.
But it had looked as though Burundi were going to get a way with a defeat - and lacklustre performance - in their game with DR Congo as Mauritania closed in on a shock win over Gabon.
Two goals from Moulaye Khalil, either side of one from Duval Nzembi, had put tournament debutants Mauritania 2-1 in front with only four minutes left, a result which would have sent Burundi through to the last eight ahead of Gabon on goal difference.
But three goals in the final four minutes plus stoppage time took Gabon from the brink of elimination to a place in the last eight.
2014 CHAN QUARTER-FINALS
- 25/1: Morocco v Nigeria; Mali v Zimbabwe
- 26/1: Gabon v Libya; Ghana v DR Congo
Aaron Ondele made it 2-2 when he headed in at the back post, sparking huge relief among his side, who had earlier hit the bar through Romuald Ntsitsigui as they desperately sought the equaliser they needed to change their fate.
Ntsitsigui hit the bar for a second time as Gabon pressed and when Bonaventure Sokambi chipped the keeper to make it 3-2, Gabon were absolutely certain of their progress and Mauritania denied their first point of the tournament.
A late penalty, dispatched by Sokambi, made it a harsh scoreline for Mauritania.
In Wednesday's other Group D game, Burundi took a 15th-minute lead against DR Congo against the run of play.
The Leopards had already had a goal disallowed - Makusu Mundele ruled to have kicked the ball out of the keeper's hands before slotting home - and had hit the woodwork through Kasusula Kilitsho's free-kick, before Selemani Ndikumana struck for Burundi.
Ndikumana finished off a counter-attack with a shot from 12 yards to stun DR Congo.
On 19 minutes DR Congo missed an opportunity to equalise when Mundele failed to convert a penalty but the forward made up for that miss six minutes later when he volleyed in to make it 1-1.
Mundele then put his side ahead on 38 minutes, connecting with a cross from the right to notch his second goal of the match, which proved enough to give his side a deserved victory.
Gabon will play Libya and DR Congo face Ghana in Sunday's quarter-finals.