(CNN) -- Hosts Brazil claimed top spot in Group A at the troubled Confederations Cup with 4-2 win over Italy in Salvador Saturday.
The match may have lacked the quality of previous classic encounters between the world football heavyweights, but burst into life in the second half.
Dante had given Brazil the lead before the break, but it needed a double from Fred and a classic free kick from home talisman Neymar to see off a determined Italian challenge.
Victory also meant Brazil will likely avoid world champions Spain in next week's semifinals.
Spain currently top Group B ahead of the final round of matches Sunday and have been in commanding form, beating minnows Tahiti 10-0 in their latest match.
Brazil have also impressed with comfortable wins over Mexico and Japan, but this has gone almost unnoticed because of the mass popular protests outside games and across the country.
Demonstrators have taken to the streets to highlight the cost of Brazil hosting next year's World Cup and the 2016 Olympics against a background of sub standard public services and corruption.
The other match Saturday in Group A in the southeastern city of Belo Horizonte, between Japan and Mexico, saw a massive rally in the streets near the Mineirao Stadium.
Police fired tear gas to attempt to disperse protesters, who had gathered despite a televised appearance late Friday by President Dilma Rousseff, who had promised changes.
Mexico beat Japan 2-1 after two goals by Manchester United's Javier Hernandez.
Before the match in Salvador at the Arena Fonte Nova, Italy coach Cesar Prandelli had advised his squad to stay inside their hotel because of security fears, but only limited protests were reported there.
Neymar proved a thorn in Italy's side from the start and was behind a flurry of attacks in the first minute.
But the rest of the half proved scrappy until the home breakthrough in added time.
Neymar whipped in a free kick and after Fred's header was palmed clear by Italian goalkeeper Gianluigi Buffon, Dante pounced to slot home the rebound.
Italy surprisingly equalized in the 51st minute as Mario Balotelli cleverly flicked on a long ball with a backheel and Emanuele Giaccherini charged forward to score.
But parity lasted just four minutes, Neymar winning a free kick on the edge of the area and stepping up to beat Buffon with a precise strike.
It was the Barcelona-bound star's 23rd goal for Brazil and sixth in his last seven games, continuing his superb form at the Confederations Cup.
Balotelli had a penalty appeal denied before Fred showed his strength to thump home the third in the 66th minute.
Shortly afterwards, Neymar, who has scored three goals in the competition, was substituted by coach Luiz Felipe Scolari, rested ahead of a last four clash in Belo Horizonte next Wednesday.
But it looked an unwise move as Italy pulled one back as Giorgio Chiellini scored with a low shot after Brazil failed to clear a corner.
Christian Maggio thumped the woodwork as Italy pushed for an equalizer but were finally defeated when Fred converted after Buffon could only push out Marcelo's shot into his path.
"We beat a strong Italian team and I think this shows we are on the right road, even if there are a few things we need to improve," Scolari told AFP.