Needing a win to stay alive, Algeria trailed by two goals at the break after Franke Kessie capped off a fine move and Ibrahim Sangare headed home.
Arsenal’s Nicolas Pepe put the Ivorians 3-0 up before Algeria captain Riyad Mahrez hit a penalty against the post.
Algeria, for whom Sofiane Bendebka scored a late consolation, exit bottom of Group E after a torrid campaign.
Djamel Belmadi’s men are the third holders to exit at the first hurdle in the past five Nations Cup finals.
Their departure from the competition is in marked contrast to their entry, travelling to Cameroon on a 34-match unbeaten run and looking to surpass Italy’s all-time record of 37.
The Algerians had drawn 0-0 with Sierra Leone before a 1-0 defeat by Equatorial Guinea, and leave with just one point from three games – but did at least finally get on the scoresheet in Cameroon when substitute Bendebka’s late goal inspired a brief rally.
Ivory Coast’s Elephants topped the group to line up a mouth-watering last-16 match with Egypt, scheduled for Douala on Wednesday, 26 January.
Algeria shell-shocked by Ivorian display
The poor pitch in the Japoma Stadium was a major talking point before the game as two recent former champions – with Ivory Coast last winning in 2015 – met in a final group tie that had the feel of the big occasion.
Algeria coach Belmadi had been baffled by his team’s lack of goals and when Ismael Bennacer clipped the post after 22 minutes, only for the Ivorians to score a minute later, he must have sensed the worst.
A sweeping move ended in Max-Alain Gradel cutting the ball back for Kessie to side-foot home, sparking huge celebrations as all 12 Ivorian substitutes charged off to celebrate with the AC Milan star and leaving goal-shy Algeria needing two goals to win.
The North Africans look shell-shocked and matters swiftly deteriorated as the Elephants converted good pressure to double their lead as Ibrahim Sangare was inexplicably left alone at the far post to powerfully head home a fine cross from the impressive Serge Aurier.
Belmadi knew his half-time talk was key but instead it was the West Africans who charged forward, forcing two good openings before Pepe delivered a trademark goal when cutting in from the right flank to stylishly curl home with his left.
Any thoughts that it was not Algeria’s day were confirmed when Mahrez, so good from 12 yards recently for Manchester City, smacked a 60th-minute penalty against the right-hand post after Youcef Belaili had been felled.
Elephants display confidence
As an army of orange-clad Ivorian fans roared their deafening approval, Ivory Coast coach Patrice Beaumelle started to rest players by making changes before Bendebka finally restored some respect for a team that lifted the trophy in Cairo three years ago.
Ajax striker Sebastien Haller thought he had added a fourth, and his second of the tournament, when heading home another Aurier cross late on, only for the goal to be ruled out for offside.
In confident form, showing real belief as well as excellent strength and purpose, Ivory Coast fully deserved a win which left Algeria’s despairing players sitting on the floor, staring into the distance in disbelief at the manner of their exit.
They became the 12th Nations Cup champions to exit the competition in the first round when defending the trophy.
The final whistle also prompted a significant pitch invasion as dozens of spectators flooded onto the grass and found themselves incredibly close to the players, before security forces belatedly restored order.
Douala is already under scrutiny for the quality of its surface – prompting suggestions matches may be moved from Cameroon’s largest city.