SAN FRANCISCO (AP) The San Francisco Giants got the victory they desperately needed.
The victory kept the Giants alone atop the NL West, a full game ahead of the Los Angeles Dodgers, who beat Pittsburgh 8-4.
The Giants were 6 1/2 games up at the All-Star break, but they entered Saturday 8-17 since, worst in the majors.
''We needed a win tonight,'' Giants manager Bruce Bochy said. ''Madison, with what he's accomplished here and the big games that he's pitched, just gives the team a sense of confidence when he's out there.''
Bumgarner (11-7) had lost five of his previous seven decisions. He allowed three hits, struck out eight and walked three.
''I made pitches and didn't give in, things just went our way that's all really you can say,'' Bumgarner said.
The Orioles fell out of first place, a half-game behind Toronto, which beat Houston 4-2.
Span sparked the Giants with two-run singles in the second and sixth innings. Both came with two outs.
''It doesn't get much bigger than that,'' Bochy said. ''Twice you come up with men on second and third and get hits. ... Timely hitting is what wins ballgames for you and of course good pitching, and Bum threw a beautiful game.''
Kevin Gausman (3-10), who hasn't won on the road this season, lasted just four innings. He struck out nine batters and walked six, becoming the first pitcher in the majors to do so since 2013.
''I thought I threw a lot of strikes,'' Gausman said. ''The most frustrating thing was on the other side (they were) getting those pitches.''
''Sometimes borderline pitches are strikes, sometime they're balls,'' Orioles manager Buck Showalter said. ''He worked a lot down in the zone and he wasn't getting the bottom of the zone. ... Anytime you walk six, there's a lot more to it than just missing. He wasn't the only one.''
Gausman fell to 0-9 on the road this season and is 0-16 in his last 25 road starts going back to Aug. 22, 2014.
Santiago Casilla faced one batter to get his 27th save.
Joe Panik had three hits, including two ground-rule doubles, and scored two runs.
''It was definitely good to get (Bumgarner) a few runs early and then tack on at the end,'' Panik said. ''He's been so good for us, he deserves some run support.
''He pitched his tail off for us tonight, so definitely a good win all the way around.''
The Giants unveiled a nine-foot bronze statue of Hall of Fame pitcher Gaylord Perry. The legendary spitballer was a five-time All-Star and two-time Cy Young Award winner. He played for the Giants for 10 years (1962-71) and is the fifth former Giant to be honored with a statue outside AT&T Park. Willie Mays, Willie McCovey, Juan Marichal and Orlando Cepeda are the others.
Orioles: RHP Darren O'Day was placed on the 15-day disabled list with a right rotator cuff strain. O'Day visited with team orthopedist Dr. Michael Jacobs and got a cortisone shot. The Orioles called up RHP Tyler Wilson from Triple-A Norfolk in a corresponding move. ... INF Steve Pearce, who missed five games with an injured flexor tendon in his right arm, wasn't in the starting lineup but was used as a pinch-hitter in the top of the seventh inning.
Giants: LHP Josh Osich, on the disabled list since July 24 with a left forearm strain, threw a bullpen session.
Orioles: LHP Wade Miley is 0-2 with a 4.91 ERA in two starts since being acquired in a trade from the Seattle Mariners. He's 4-4 with a 3.23 ERA in 10 games (nine starts) against San Francisco.
Giants: RHP Johnny Cueto is 0-2 with a 5.02 ERA in six starts since the All-Star break after going 13-1 with a 2.47 ERA in the first half. He is 0-2 with a 10.32 ERA in two career starts against Baltimore.