Igor Akinfeev was Russia's hero after saving two penalties in a shoot-out to sensationally dump Spain out of the World Cup and book the hosts a place in the quarter-finals after a 1-1 draw in Moscow.
Koke and Iago Aspas were denied by the Russia goalkeeper as 2010 champions Spain, who dominated possession without creating clear chances, were defeated 4-3 on penalties.
Sergei Ignashevich became the oldest scorer of an own goal in World Cup history when the 38-year-old gave Spain an early lead at the Luzhniki Stadium.
A right-wing Isco cross isolated Ignashevich and Sergio Ramos at the back post, the Russia defender turning the ball home via his heel as he desperately tried to block his opponent's run.
But Russia drew level in the 41st minute, Artem Dzyuba smashing home a penalty after his header was blocked by Gerard Pique's arm in the box.
A stodgy Spain could not break the hosts down and were denied a penalty following a VAR review in extra-time, sending the tie to a shoot-out.
Akinfeev saved a terrible Koke penalty to put Russia in control and with David de Gea unable to stop any of the four kicks he faced, Aspas' effort was brilliantly blocked by the goalkeeper to spark chaotic celebrations.
Aleksandr Golovin's early break down the right raised excitement levels among Russia's loud following, but his cross was blocked and Aleksandr Samedov's resulting corner was too deep.
Spain then took the lead from a more accurate set-piece in the 12th minute.
Isco's free-kick from deep on the right saw Ignashevich grappling with Ramos at the back post, the ball inadvertently bouncing past Akinfeev off the veteran defender's heel, although Spain's captain tried to claim the goal.
Spain were dominating possession but complacency edged into their game and the next big chance fell to Russia in the 36th minute, Golovin bending a shot wide after Dzyuba held off Ramos to win a header.
And Russia were then gifted a penalty when Pique handled in the box.
Dzyuba - whose header was blocked by the defender's arm - crashed home from 12 yards to send the sides into half-time level after Akinfeev did well to deny Diego Costa.
Jordi Alba and Costa missed efforts after the restart as Spain tried to increase their tempo.
Russia coach Stanislav Cherchesov could smell a major upset, introducing Villarreal midfielder Denis Cheryshev, who hit three goals in the group stage, while Spain sent for Andres Iniesta, who had started 21 consecutive matches at international tournaments.
And it was Iniesta who almost came up with the winner in the 85th minute, Akinfeev getting down low to his right to save, the goalkeeper then denying Iago Aspas on the rebound.
Akinfeev claimed Pique's header and pushed away a Rodrigo Moreno shot in extra-time, while the introduction of Aleksandr Erokhin as Russia's fourth substitute made World Cup history.
Pique and Ramos both appeared to be held from a set-piece but, after a VAR check, referee Bjorn Kuipers waved away Spain's desperate appeals.
Host nations had won each of their last four shoot-outs and when Akinfeev easily kept out a tame Koke effort, Russia were on track for one of the biggest shocks in World Cup history.
De Gea's miserable World Cup was complete as he was beaten by all four Russia penalties, piling the pressure on Aspas, who saw his effort diverted away by the leg of home hero Akinfeev.
Russia's first win over Spain since the breakup of the Soviet Union books the hosts a place in the quarter-finals, where either Denmark or Croatia await.