(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.
There were no reported protests outside a packed Arena Fonte Nova for the final group game although Cesar Prandelli had advised his Italian squad to stay inside their hotel prior to the match.
Neymar proved a thorn in their 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.
In the other Group A match, Mexico beat Japan 2-1 with Manchester United's Javier Hernandez scoring both their goals.
After Shinji Okazaki pulled one back for Japan, Hernandez saw his late penalty saved as he sought his hat-trick, but his side hung on.