The Congolese finished top of the standings after beating Togo 3-1 in Port Gentil while Morocco eliminated holders Ivory Coast with a 1-0 victory in Oyem.
The Ivorian exit adds to the earlier shock elimination of hosts Gabon and pre-tournament favourites Algeria while Togo finished last in Group C, bringing down the curtain on the participation of Emmanuel Adebayor and record-breaking coach Claude Le Roy.
The Ivorians departed with just two points with veteran Salomon Kalou announcing his retirement from international football afterwards and coach Michel Dussuyer suggesting his future is far from secure.
“For now, I am extremely disappointed because we have not met our objectives. Our ambition was to get past this first round and go on and keep our title. The night is going to be difficult. Wait till tomorrow,” he told reporters.
Rachid Alioui scored a spectacular winner from 35 metres to secure progress for Morocco, whose coach Herve Renard took the Ivorians to their title two years ago.
The 24-year-old, who plays for Nimes in the French second division, picked up the ball, spotted the goalkeeper off his line and masterfully curled his shot into the top corner.
Morocco now play the winners of Group D which will be settled on Wednesday.
Junior Kabananga scored his third goal of the tournament to give DR Congo the halftime lead and they added two more through Ndombe Mubele and Paul-Jose Mpoku while Kodjo Laba pulled one back for Togo.
Kabananga has now scored in all three Group C games, his latest goal coming as he ran on to a superb defence-splitting pass from Newcastle United’s Chancel Mbemba just before the half hour.
Togo’s failure to qualify marked only the second time in eight tournaments that Le Roy, who has been to more Nations Cups than any other coach, had failed to place a team in the last eight.
It could also have been the last international for Adebayor, their talismanic captain, who was denied a consolation goal in stoppage time when Merveille Bope cleared off the line.
“I am going now to think about whether I continue but I feel like I’m the captain of the boat and I’m not sure whether I should climb out yet,” Adebayor said.
After the final whistle, the Congolese team formed a guard of honour to applaud him off the field.