PHOENIX -- Dan Haren got his birthday party started a little early.

Haren, who will celebrate his 28th birthday Wednesday, threw his first career shutout Tuesday night at Chase Field, allowing just four hits as the D-backs edged the Giants, 2-0, in front of 33,195.

It was Haren's sixth career complete game and it was just what he needed to quell any rumors that he may be injured after he had put together a string of less-than-average outings. Haren (15-8) hadn't won since Aug. 20, a span of four starts. In his last three starts, he had allowed 12 runs through 14 innings.

On Tuesday, he was lights-out, tying his career-high with 12 strikeouts and needing 117 pitches to finish off the Giants, the same team against which he threw 99 pitches through four innings in his last start Wednesday, picking up a no-decision in San Francisco.

"Obviously, I had my struggles, but it's nice to get this feeling again," Haren said. "I've been searching for it for a while.

"I really didn't do much different, to be honest. I just had a different mentality. ... Maybe I was trying to do too much, maybe trying to go out there and throw a complete-game shutout rather than just go out there and pitching."

And boy, did he pitch. The D-backs offense hasn't exactly been lighting up the scoreboard recently, but with Haren's command on the mound Tuesday, it didn't need to do much.

Accounting for all the game's runs, catcher Chris Snyder had a solo home run in the fourth inning, followed by a sixth-inning solo shot from shortstop Stephen Drew, who was making his return to the D-backs after spending the last two days in Georgia for his grandmother's funeral.

"The way he was going, that was all he needed," Snyder said. "He carried us. ... He had everything going tonight."

Following a Dodgers win, the D-backs remained 4 1/2 games out of first place. The Dodgers' magic number is down to eight. The win meant it was the first time since Aug. 20-21 that the D-backs got consecutive wins, part of the reason they find themselves looking up at the Dodgers in the standings now.

Haren completed quite the cycle for the D-backs starting rotation. Through the first five games of the homestand, the entire rotation has compiled a 0.50 ERA, but the team has just three wins to show for it. In the five games, the offense has scored 11 runs, but Arizona will take the consecutive wins.

You could almost sense the mood in the clubhouse after the game lightening up.

"It's always going to be more fun when you're winning, but even if it's going bad, we've still got to enjoy the last bit of the season," Snyder said. "If there's going to be a postseason, we don't know right now. Anything can happen. It's a crazy game. We've just got to enjoy it."

Haren paced the D-backs to a quick two-hour-and-six-minute game, just one night after a two-hour-and-19-minute game started by Doug Davis.

The right-hander allowed a single in the fourth inning to Pablo Sandoval and a double in the seventh to pinch-hitter Conor Gillaspie, his first big league hit. In the ninth, Randy Winn and Sandoval had consecutive singles, but Haren stranded both runners after getting Bengie Molina to fly out and Travis Ishikawa to strike out on a nasty backdoor slider. Haren also got some solid defense behind him from Chad Tracy and Augie Ojeda.

"You could tell early on he had that focus back in his eye," D-backs manager Bob Melvin said. "He kind of worked some kinks out as far as mentally about throwing the ball over the plate."

Melvin said he had no qualms about leaving Haren in for the ninth, despite entering with 101 pitches.

"I thought his stuff was just as good in the eighth as it was in the third, so he deserved to go back out there," Melvin said.

Haren admitted he had lost a bit of confidence in his stuff recently after getting roughed up in the last few outings, but Tuesday, he seemed to get it all back.

"He was the same pitcher," Snyder said. "He just had a stretch of bad luck. He worked it all out and he was effective tonight."