He allowed four hits and four walks while striking out three. McDonald (1-2) lowered his ERA to 7.66 from 10.13.
"It feels like I got a monkey off my back with the first win," McDonald said. "I feel a little less stress now."
Bumgarner (0-4) remained winless despite allowing only one run and five hits in six innings with one walk and seven strikeouts. He cut his ERA to 6.17 from 7.79, but the Giants lost for the fifth time in six games to fall below .500 at 11-12.
"I thought Madison did a great job," San Francisco manager Bruce Bochy said. "He kept his poise and stayed away from the crooked number that has killed him. It's tough to not get runs for him. It'd be big to get him his first win."
Mike Crotta, Joe Beimel, Chris Resop and Joel Hanrahan completed the five-hitter for Pittsburgh. Hanrahan recorded his seventh save in seven opportunities, getting Miguel Tejada to ground into a game-ending double play with runners on first and second.
The announced attendance was 9,048 the number of tickets sold but the actual turnstile count appeared much smaller. The crowd was held down because the Pittsburgh Penguins and Tampa Bay Lightning were playing across town in Game 7 of their first-round Stanley Cup playoff series.
The Penguins lost 1-0.
McDonald was tagged for eight runs in three innings at Florida in his previous start six days earlier. Pirates catcher Chris Snyder said the difference this time was that McDonald didn't rely as much on his fastball and threw more curveballs and changeups.
"He mixed it up really well," Snyder said. "He needed that start. He needed to get something going, something to give him confidence."
McDonald also got his ERA back into three digits after allowing 21 earned runs in 18 2/3 innings in his first four starts. However, against the Giants, McDonald looked more like the pitcher who went 4-5 with a 3.52 ERA in 11 starts last season after being acquired from the Los Angeles Dodgers at the July 31 trading deadline.
"The best way to knock down an ERA is to put up zeros and that's exactly what James did," Pittsburgh manager Clint Hurdle said. "He did a great job."
Bumgarner, like McDonald, was coming off a rough start as he allowed four runs in 2 2/3 innings against Atlanta last Friday. While he did not get a win, Bumgarner believed he made progress.
"I felt smoother and worked out of some jams," he said. "I really was taking it one inning at a time instead of looking at the whole ballgame at once."
Walker scored the game's first run in the second inning when he singled off Bumgarner's glove, took third on Pearce's double and scored on Snyder's hit into center field. Tabata's two-out single to right field off Guillermo Mota in the seventh scored Brandon Wood, who had singled, and made it 2-0.
San Francisco's best scoring chance came in the second inning when it put runners on second and third with one out. However, McDonald got Tejada and Bumgarner to ground out to end the threat.
The Giants have scored just 14 runs in their last six games while hitting .188 with only one home run.
San Francisco INF Mark DeRosa is likely to be placed on the disabled list Thursday because of inflammation in his left wrist, which was surgically repaired each of the last two years. Triple-A Fresno INF Emmanuel Burriss was scheduled to arrive in Pittsburgh late Wednesday night in order to be available to play in Thursday afternoon's game if DeRosa goes on the DL. OF Xavier Paul, claimed off waivers from the Los Angeles Dodgers on Tuesday, arrived in the Pittsburgh clubhouse following the game. OF John Bowker said he was told by the Pirates that he will be designated for assignment on Thursday to clear a roster space for Paul. Pittsburgh 1B Lyle Overbay, who has only one extra-base hit in his last 14 games, was not in the lineup for the second time in three games, and SS Ronny Cedeno was benched a night after failing to run out a groundball in a 3-2 loss to the Giants in 10 innings. San Francisco RHP Ryan Vogelsong is scheduled to make his first major league start since Sept. 29, 2004, on Thursday. Vogelsong's last start came for Pittsburgh.
Buster's Buzz: Red Sox repeat? Four question marks facing the champs
From health to hangovers, Boston still must find a few answers in its quest for a second straight ring.
Yankees sign reliever who criticized Babe Ruth
Mike Golic finds it comical that the Yankees signed reliever Adam Ottavino who previously stated he would "strike out Babe Ruth every time."
Mariano Rivera, Lee Smith and what makes a Hall of Fame closer
One is a first-ballot lock. The other a last-chance inductee. Here's what Cooperstown's 2019 ninth-inning stars tell us about Hall standards for the position.
Red Sox manager Alex Cora may reconsider decision to visit White House
Red Sox manager Alex Cora, a Puerto Rico native who has been outspoken about its need for hurricane relief, indicated on Thursday that he may skip the World Series celebration at the White House over President Trump's policies toward the island.
Forget Babe Ruth, Yankees get the guy who could strike him out
Adding Adam Ottavino -- who boasted he'd whiff the Bambino "every time" -- gives the Bombers the best bullpen in the universe.
Could these 'mystery teams' be in on Manny Machado, Bryce Harper?
Are the Yankees set to swoop in on Manny after all? Who might be biding their time for Bryce? We look at some of the potential surprise suitors insiders are talking about.