Rivera drove in three runs with a bases-loaded double in the bottom of the sixth inning.
David Bell hit a two-run homer and scored twice for the Brewers (73-83), who have a five-game winning streak.
Winner Ben Sheets (6-7) scattered two runs and five hits over eight innings with no walks and six strikeouts.
Francisco Cordero recorded his 16th save.
Eliezer Alfonzo, Tomas de la Rosa, and Pedro Feliz all had one RBI; while Feliz and Alfonzo both had two hits for the Giants (75-80), who were all but eliminated from the post-season chase after the eight loss in their last 10 games.
The losing pitcher was Matt Cain (13-11).