Serie A leaders Juventus scored twice in the last five minutes to win 3-2 at Inter Milan who had earlier come from behind to lead despite playing with 10 men in an extraordinary match on Saturday.
The Turin side were facing an embarrassing defeat which would have left the door open for title rivals Napoli until Juan Cuadrado's shot went in off Milan Skriniar with three minutes left and Gonzalo Higuain headed a winner at a stunned San Siro.
Juve's win took them four points clear of Napoli, who visit Fiorentina on Sunday, and ensured they will finish the weekend top of the table with three matches to play.
Inter, chasing a top-four finish that would qualify them for the Champions League group stage, stayed fifth.
Still smarting from last week's home defeat by Napoli which threw open the title race, Juventus got off to a flying start when Douglas Costa collected Cuadrado's crossfield pass and scored from a narrow angle in the 13th minute.
Inter were in more trouble when midfielder Matias Vecino was dismissed five minutes later, the referee initially showing a yellow card for his tackle on Mario Mandzukic before changing to red after consulting the video assistant referee (VAR).
Juventus, who had coach Massimiliano Allegri sent off after the winning goal, thought they had scored a second in first-half stoppage time but the goal was revoked for offside after a VAR consultation.
Against all the odds, Inter turned the game around as Mauro Icardi equalised shortly after halftime and veteran Juventus defender Andrea Barzagli turned Ivan Perisic's low cross into his own net.
Juve were facing a dramatic defeat until Cuadrado's shot from an impossible angle deflected in off Skriniar with three minutes left.
A trademark late Juventus winner was in the air and it materialised when Paulo Dybala floated over a free kick and Higuain, who had earlier missed two good chances, powered in a header in the 89th minute.
"It was a great evening of football between two teams who faced each other openly," said Allegri. "We were very good in the first half, very aggressive. But we went to sleep in the dressing-room... In the end, it's the great players who decide matches."
ROMA RUN RIOT
Earlier, AS Roma warmed up for their Champions League return against Liverpool by thumping Chievo 4-1 despite playing the last half hour with 10 men.
Edin Dzeko scored twice as Roma, who will attempt to overturn a three-goal deficit in Wednesday's semi-final second leg against the Premier League side, ensured they will finish the weekend in third place.
Patrik Schick turned in Radja Nainggolan's pass and Dzeko volleyed in from Aleksandar Kolarov's cross as Roma took a 2-0 halftime lead against the Flying Donkeys.
Chievo were awarded a penalty in the 56th minute when Roma defender Juan Jesus hauled back Roberto Inglese in the penalty area. Jesus was sent off but Inglese saw his spot kick saved by Alisson.
Stephan El Shaarawy added Roma's third with a solo goal and Dzeko completed the rout when he curled home an equally impressive effort from outside the area.
Inglese headed a consolation for Chievo who are only one place and two points clear of the relegation zone.