Spurs sealed qualification for the Champions League knockout stages in the most dramatic style, with two goals from Alli and one from Christian Eriksen ensuring a memorable night at Wembley.
The home fans were even cheering their side’s every pass with 20 minutes left as Mauricio Pochettino’s men threatened to humiliate their star-studded opponents before Cristiano Ronaldo added a late consolation.
Victory means Tottenham move top of Group H on 10 points, three ahead of their Spanish opponents with two games remaining.
The last time Spurs overcame the European champions was in 2010 when Gareth Bale inspired them to beat Inter Milan by the same scoreline, but this was nothing if not a team performance.
Harry Kane, having overcome a hamstring injury, was irrepressible up front while Eriksen, Harry Winks and Kieran Trippier, along with Alli, could all lay claim to leaving as man of the match.
England manager Gareth Southgate, watching on in the stands, must have liked what he saw.
Real were admittedly hampered by injury, with Raphael Varane, Bale and Keylor Navas all absent – but that will do little to comfort the under-pressure Zinedine Zidane. After losing to Girona in La Liga on Sunday, this was the first time they had been beaten in a Champions League group match in 31 attempts.
They started brightly, Ronaldo, pictured, welcoming Trippier with some trademark step-overs and then switching to the other flank to taunt Ben Davies with a flicked pass behind his legs. But, after a nervy start, Tottenham soon found their rhythm and Kane threatened before Trippier’s volley was just ahead of Alli at the far post. It was almost an exact replica of the opening goal to come.
Winks’ single fault of the half was to snatch at a shot after Marcelo’s rash clearance and then Toby Alderweireld was forced off with a hamstring injury.
Moussa Sissoko replaced him and Eric Dier dropped into defence but Tottenham were not deterred. Instead they took the lead when Trippier again volleyed first time across the box and this time Alli read it, nipping ahead of Nacho to poke home. The remaining 18 minutes of the first half were end to end as Tottenham sniffed a second but risked conceding an equaliser.
Ronaldo twice went close, his first attempt the result of a dummy that had Davinson Sanchez doing a pirouette.
But Spurs survived and Pochettino thought they deserved a penalty when Alli went down after a tangle with Casemiro. Referee Cuneyt Cakir judged Casemiro to have won the ball first.
Madrid emerged with renewed vigour after half-time but, 11 minutes in, Tottenham had a second. Eriksen allowed Dier’s pass to run through to Alli, who skipped past Nacho and let fly. His shot deflected off Sergio Ramos and in at the near post.
Ronaldo stood with his hands on his hips and his frustration grew when a scramble in the area ended with his shot being blocked by team-mate Ramos. There was worse to come. In the 65th minute, Alli freed Kane on the counter, who slid found Eriksen. The Dane was all on his own and rolled the ball past Casilla for No 3.
Alli should have had a hat-trick when he headed another Trippier cross wide and Pochettino’s substitution of Kane felt premature when Ronaldo drilled home from close range.
The final ten minutes were nervier than they might have been but Tottenham held firm for a landmark European victory.