Algeria booked their place in the last 16 of the World Cup for the first time in their history with a 1-1 draw against Russia in Curitiba.
Aleksandr Kokorin gave Russia a sixth-minute lead, which would have earned Fabio Capello's team a clash against Germany in Porto Alegre on Monday.
However, Islam Slimani netted on the hour to ensure it was the north Africans who progress from Group H behind Belgium.
It did not look good for Algeria, impressive conquerors of South Korea last time out, when they fell behind inside six minutes at the Arena da Baixada.
Dmitri Kombarov advanced down the left and sent in an inviting cross which Kokorin powered into the top corner of the net past Rais Mbolhi from 12 yards.
Algeria should have had a penalty when Slimani was tugged in the box by Aleksei Kozlov - but referee Cuneyt Cakir did not penalise the offence.
Oleg Shatov came close to doubling Russia's lead in the 26th minute, with a dipping shot from more than 20 yards narrowly off target, before S limani brought a good save out of goalkeeper Igor Akinfeev from 10 yards at the other end three minutes later.
Yacine Brahimi tried his luck with a low drive in the 35th minute - but it did not carry enough power to seriously challenge Akinfeev, who gathered comfortably.
Mbolhi was the first goalkeeper called into action in the second half, making an excellent stop to deny Aleksandr Samedov within two minutes of the restart.
Both Russian full-backs, Kombarov and Kozlov, picked up bookings within the space of less than three minutes as Algeria threatened down the flanks - a nd the second free-kick brought about the equaliser, just before the hour mark.
Akinfeev failed to cut out the resulting free-kick - taken by Brahimi - and Slimani took advantage of space at the back post to head home his second goal of the tournament, from five yards.
Kerzhakov tested Mbolhi with a low shot in the 70th minute, then Kokorin saw a shot blocked soon after as Russia sought the goal they needed to continue their interest in the tournament.
However, the 2018 hosts created little in the closing stages of the contest and when Cakir blew his whistle, they exited the competition while Algeria were looking forward to a match against Germany - who they beat in the group stages of the 1982 World Cup.