The Brewers won for the first time in three tries and the Giants have dropped four straight.
San Francisco rallied to tie it with a three-run sixth against starter Zack Greinke but the Brewers quickly regained the lead and kept it the rest of the way.
Both Norichika Aoki and Rickie Weeks reached on one-out, infield singles in the seventh off Clay Hensley (1-3). Sergio Romo came on to replace Hensley and got Corey Hart on a fly ball to deep center, but Aoki and Weeks were both able to take up and advance.
Ramirez was next and his single on an 0-1 pitch delivered both runners.