Brazil’s Fred, right, and Uruguay’s Diego Lugano challenge for the ball during their Confederations Cup semi-final match on Wednesday at the Estadio Mineirao in Belo Horizonte, Brazil.

Photo: Reuters

A towering Paulinho header saw Brazil edge Uruguay 2-1 on Wednesday in an ill-tempered Confederations Cup semi-final in Belo Horizonte to set up a final with either world champions Spain or Italy.

Fred scored from close range two minutes from half-time to calm the nerves of the five-time world champions and Confederations Cup title holders after Diego Forlan had first missed a penalty for Uruguay.

However, Edinson Cavani levelled three minutes after the restart and thereafter the hosts were rocking before Paulinho rose high to plant a firm close-range header past Fernando Muslera in the Uruguay goal to pull off a barely deserved victory.

“A Brazil match against Uruguay is always really an emotional rollercoaster for me,” said Brazil goalkeeper Julio Cesar, who said he knew Forlan would fire his penalty to his left.

“I played with him at Inter Milan — but it was a good stop,” he said.

Cavani said the penalty miss was “a shame as we were playing well but we have to take it on the chin.”

Uruguay coach Oscar Tabarez, who led Uruguay to the Copa America title in 2011 to book a berth here, was sanguine afterwards.

“We played with passion and made it tough for them, but we will learn from the experience,” Tabarez said.

Matches between the South American neighbors have long been tense affairs — not least since the Uruguayans shocked the Brazilians in the 1950 World Cup final in Rio to deny their hosts a first title.

However, what gave this meeting added spice were pre-match comments by Uruguayan skipper Diego Lugano labelling Brazilian starlet Neymar a diver.

The Brazilian Football Confederation issued a furious rebuttal of the claim, but there was clearly no love lost between the sides as they snapped into tackles and scrapped for every bit of territory.

Brazil made a sluggish start and Lugano was to the fore as he won a penalty for the Uruguayans after 16 minutes.

The veteran defender tussled with Chelsea centerback David Luiz in the box and went down — but Chilean referee Enrique Osses quickly spotted that Luiz had tugged on his rival’s shirt and gave the spotkick.

Uruguay’s record goalscorer Forlan stepped forward, but placed his low kick too close to Julio Cesar, the ’keeper diving away to his left to push the ball round the post and elicit a deafening cheer from a 60,000 crowd at the Estadio Mineirao.

Around twice that number were in the streets, kept out by a police cordon as they joined yet another protest against crumbling public services and government corruption as well as the multibillion dollar bill for staging major sporting events.

Police said beforehand they expected trouble but Brazil, mindful of coach Luiz Felipe Scolari’s urging them to make their countrymen proud, finally awoke from their nervy slumbers and took the lead two minutes before the break with their first chance of note.

Neymar chased a long punt down the left and stretched to flick the ball across goal for Fred to poke home a scissor kick finish from the edge of the six yard box, sparking pandemonium in the crowd.

By then, Neymar had certainly spent some time on his back — yet the Barcelona-bound 21-year-old was a marked man as Cavani earned a booking for yanking him back.

Yet Brazil were still nowhere near to finding the flowing form which had brought three wins and nine goals in the group stage and three minutes after the restart Uruguay were level through Cavani, the Napoli man threading a left-foot strike past Cesar.