"That's one of those ground balls, you see it at first, you say, 'Oh, that's an out,'" Cain said. "This infield is pretty quick here sometimes. It was a sweet play."
Velez also reached base three times and scored what became the winning run. In the process, the Giants inched closer in the National League Wild Card race, pulling within a half-game of Colorado.
Cain (13-4), held without a victory since July 24 despite a 3.10 ERA in the outings since, delivered seven-plus superb innings, holding the Brewers to four hits.
"He's bullstrong," Giants manager Bruce Bochy said. "This kid can throw a lot of pitches and innings. He got out of sync there a little bit, but he's our guy and we knew he'd get out of it. He settled down, made some pitches. That's the difference between Matt this year and last."
After retiring eight consecutive batters, Cain issued walks to the first two men in the seventh but kept a run off the scoreboard. He allowed a leadoff double to Jason Kendall in the eighth -- a runner that later came around to score -- and was lifted for Jeremy Affeldt.
"It took awhile," Cain said of the win drought. "The bullpen picked me up. Going against [Brewers starter Yovani] Gallardo, it's not going to be easy. Not a lot of runs."
Juan Uribe homered with two outs in the fourth, and Aaron Rowand followed two batters later with an RBI single to spot the Giants a 2-0 lead. After Fielder's RBI double cut the lead in half, Velez tripled to lead off the fifth and scored on Randy Winn's double.
"Velez wasn't getting a lot of playing time, and he went down to [Triple-A] Fresno, worked on his game and has done a great job slowing down the game," Bochy said. "He's a different player. The consistent playing time in Fresno helped him."
Starting just his 12th game at second base, Velez had to run farther than normal in the eighth, overcoming the defensive shift on the left-handed Fielder to play the bouncer up the middle.
The flip to Uribe at the bag cut down a speedy Ryan Braun.
"I thought it was clearly going to go through," Brewers manager Ken Macha said.
"I think we all did," said Brewers right fielder Jody Gerut.
On the hill was Brian Wilson, who entered the game in relief of Affeldt in the eighth with one down and two on. The Miller Park radar gun registered pitches in excess of 100 mph at the start of his outing, but he still had enough to clamp down his 34th save.
"I felt like I was throwing a little harder," Wilson said. "They're a fastball-hitting team, and I'm a fastball pitcher."
Wilson has exceeded one inning in seven of his saves this season.
"I'm used to it," Wilson said. "You have be prepared for any inning, whatever you can do to help out the club. This is a race. This is no time to sit and wait. If they need me in the eighth, the seventh, whatever. Go out there and get the outs and pass the buck on to the next guy."
Bochy had high praise for his top ninth-inning option.
"He's emerging as one of the top closers in the game," Bochy said. "He's in the eighth with one out -- a lot of guys don't do that. But he's so strong, and I'm comfortable bringing him in the eighth. He faced some tough hitters there and got out of it."
San Francisco entered the series having won four of its previous 20 games in Miller Park, but after successive victories, the Giants moved to a season-high 14 games over .500.