An early own goal and strikes from Daniel Candeias and Glenn Middleton each put Rangers ahead and Alfredo Morelos had a goal controversially ruled out for offside with the visitors 3-2 in front near the end of a breathless first half.
But Luiz Adriano headed another equaliser in the 58th minute and Connor Goldson - who scored a first-half own goal - inadvertently diverted Sofiane Hanni’s strike into the net seconds later.
Nikola Katic hit a post for Rangers in time added on to an extraordinary game.
The result blew open Group G as Rangers, pre-match leaders, slipped to third, one point behind Villarreal and one ahead of Rapid Vienna.
Middleton was handed his second start for Rangers after a hamstring injury ruled out Ryan Kent while Katic was also among five players brought in following Saturday’s victory over St Mirren.
Spartak caretaker boss Raul Riancho had accused fans of trying to destroy their club after they reacted angrily following a fourth consecutive home defeat in the league and his name was roundly booed before the game.
But the home supporters got behind their team from the start and Roman Zobnin came close to rewarding them with a long-range strike.
The goal spree began inside five minutes as Roman Eremenko headed Middleton’s corner into his own net under pressure from Lassana Coulibaly.
The hosts responded well and Allan McGregor made two stops from Salvatore Bocchetti before being beaten in the 22nd minute by Lorenzo Melgarejo’s back-post header after Ivelin Popov turned Jon Flanagan one way and the other before delivering an excellent cross.
• READ MORE - Spartak Moscow 4-3 Rangers: As it happened
Popov beat Flanagan in the air but headed over but the Rangers left-back soon enjoyed a better moment as Rangers regained the lead in the 27th minute.
Flanagan’s through ball found Candeias unmarked as the winger beat the offside trap before producing a brilliant 18-yard finish.
Middleton soon saw a low cross turned just wide by a Spartak defender but there was an own goal at the other end in the 35th minute as Goldson sliced a clearance past McGregor after Nikolai Rasskazov had run on to a pass inside Flanagan and delivered a low cross.
Rangers were back in front six minutes later when Middleton drilled home after getting the break of the ball following some direct running from Morelos.
The Colombian swept home a Candeias cross moments later but was denied by a dubious offside decision.
The break failed to halt the momentum. McGregor made a good stop from Hanni within two minutes of the restart and Rangers threatened on the break before the third equaliser. Again McGregor saved from Hanni but the ball looped up for Adriano to head home.
Hanni got his goal a minute later when his long-range strike clipped the boot of Goldson and flew into the top corner.
Bocchetti headed against the bar as Spartak took control but there was still more drama as Katic headed against a post from a stoppage-time corner before the hosts scrambled the ball behind.
Gareth McAuley was thrown on for a debut but Spartak survived the second set-piece to clinch victory.