Both teams scored in a five-minute spell before half-time when Andrezinho gave Botafogo the lead before Damian Escudero replied for Mineiro, scoring from a rebound at the end of a move started by Ronaldinho.
Ronaldinho was involved again as the Roosters took the lead after the break, laying the ball into the path of former Manchester City and Everton striker Jo to make it 2-1, only for Andrezinho to level from a penalty with 10 minutes to go.
Neto Berola struck the winner with two minutes left to leave his side three points clear of Fluminense, who won 1-0 at home to Sport Recife.
Former CSKA Moscow forward Vagner Love scored the only goal to give Flamengo victory over arch-rivals Vasco da Gama, although they should have added another in the second half when Leo Moura somehow missed an open goal from six metres.
Santos won their second game in four days since the return of Neymar from the Olympic Games, coming from behind to beat South American champions Corinthians 3-2.
Luiz Felipe Scolari's problems continued as the former Brazil and Portugal coach's Palmeiras side lost 2-1 at Atletico Goianiense to drop back into the relegation zone.