Flu appeared to be cruising to victory when Fred put them ahead on the stroke of half-time and an own goal from Mauricio Ramos doubled the advantage nine minutes after the break.
Palmeiras stormed back with goals from Hernan Barcos in the 62nd minute and Patrick Vieira three minutes later, but Fred struck two minutes from time to seal the win.
It put them 10 points clear of Gremio, who beat Sao Paulo 2-1, with three games to go and secured their fourth league title.
Palmeiras were left second bottom, seven points from safety and staring relegation in the face despite having qualified for the Copa Libertadores courtesy of their Copa do Brasil victory.
Flu would still have had to wait had Atletico Mineiro won at Vasco da Gama but they could only draw 1-1.
Ronaldinho opened the scoring for Atletico in the 27th minute but their chances were hit when Serginho Mineiro was sent off four minutes from half-time.
Alecsandro duly levelled in the 56th minute but Vasco could not find a winner and the numbers were evened up seven minutes from the end when Douglas saw red.
That allowed Gremio to leap above them, second-half goals from Andre Lima (61) and Marcelo Moreno (85) giving them the win over Sao Paulo, who had opened the scoring through Rogerio Ceni's penalty just before the break.
Sport Recife were denied victory but still claimed a useful point in their relegation battle with a 1-1 draw at Figueirense.
Gilberto put Sport ahead in the 24th minutes, but Julio Cesar levelled in the 64th minute.
It left them three points behind Bahia, who occupy the last position of safety after losing 3-1 to Cruzeiro.
Leandro Matos put Bahia ahead in the 28th minute, but two second-half strikes from Alejandro Martinuccio and another from Willian Antunes (90), which came after Alessandro had been sent off (86), gave the points to Cruzeiro.
Elsewhere, Renato Abreu's 82nd-minute penalty gave Flamengo a 1-0 win at Nautico Recife, while Roger's first-half goal saw Ponte Preta beat Internacional by the same scoreline.