Juventus, the Serie A leaders, scored twice in the last five minutes to win 3-2 at Internazionale, who had earlier come from behind to lead despite playing with 10 men in an extraordinary match in Milan.

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. But it had looked as if they were going to concede potentially critical ground until the dramatic finale.

The Turin side were facing an embarrassing defeat which would have left the door open for their title rivals Napoli until Juan Cuadrado’s shot went in off Milan Skriniar with three minutes left and then Gonzalo Higuaín headed a winner at a stunned San Siro. 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 Matías 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 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 round as Mauro Icardi equalised shortly after half-time and the veteran Juventus defender Andrea Barzagli turned Ivan Perisic’s low cross into his own net.

In between those two goals there was controversy when Juve’s Miralem Pjanic brought down Rafinha with a very clumsy, very high tackle. He was already on a booking – and, when the referee took out his card again, many thought it would be a second yellow and a red. But in fact he booked Rafinha’s team-mate D’Ambrosio for dissent.

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 Higuaín, 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 Juve’s coach, Massimiliano Allegri, who was sent off after the winning goal. “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.”

In the earlier game, Edin Dzeko struck twice for Roma in the 4-1 win over Chievo. Patrik Schick opened the scoring before Dzeko put the home side 2-0 up. Juan Jesus was sent off in the 55th minute but Stephan El Shaarawy and Dzeko added further goals. Roberto Inglese scored a late consolation for the relegation-threatened visitors.

Sevilla sack Montella, Bale fires Real to win

Sevilla have sacked their Italian coach, Vincenzo Montella, and reappointed their former manager Joaquín Caparrós until the end of the season. Montella suffered an eighth La Liga defeat in 17 games since succeeding Eduardo Berizzo in December as Sevilla fell to a 2-1 defeat at struggling Levante on Friday.

Real Madrid beat Leganès 2-1 after Zinedine Zidane rotated his side in preparation for Tuesday’s Champions League semi-final second leg against Bayern Munich. Gareth Bale, who was left on the bench for the first leg, and Borja Mayoral scored the Madrid goals.

Hamburg earn priceless win, Cologne go down

Hamburg secured a potentially priceless 3-1 victory at Wolfsburg to improve their chances of remaining in the Bundesliga next season. Goals from Bobby Wood and Lewis Holtby set Hamburg on their way to a third win in four games, with Gian-Luca Waldschmidt adding a late third. Hamburg, who have never been relegated from the Bundesliga, are now two points behind both Wolfsburg and Mainz.

Cologne’s inevitable drop into the second tier was confirmed as they lost 3-2 to Freiburg. Lucas Holer scored a late winner after Leonardo Bittencourt had pulled Cologne level with two late goals. In the second tier, Rouwen Hennings scored in the 90th minute as Fortuna Düsseldorf beat Dynamo Dresden and booked their return to the Bundesliga after a four-year absence.