PHOENIX -- Three-run lead. Three outs from a six-game winning streak. The Giants on the verge of going from hot to scalding. The ball in Brian Wilson's hand.

"You'd think we've got the game in the bag," said Wilson.

But it turned out to be a sandbag. And after the Diamondbacks sandbagged his Giants for a 5-4 win in 12 innings, manager Bruce Bochy could only rue falling victim to breaking one of the Ten Commandments.

"Winning two out of three is not bad. But after taking the first two, you get greedy," Bochy said.

On their way to opening a series against the rival and National League West-leading Dodgers on a high, Wilson and the Giants were struck by ninth-inning lightning. The loudest crackle came on Justin Upton's game-tying two-run homer, a laser shot with barely enough height to clear the wall in straightaway left.

Three innings later, Conor Jackson delivered a one-out, bases-loaded single over a drawn-in outfield for the winner.

But the Giants had been dangling on the cliff's edge since the ninth.

"Certainly, it's disappointing," said Wilson, who'd been flawless in his previous three save chances this season. "I just wasn't able to locate my pitches. I couldn't get the fastball in the zone, and the slider kept drifting outside."

"He was just off," said Bochy. "We were in the situation we'd hoped for, but he just had an off day."

In addition to the winning streak, Wilson spoiled banner days by starting pitcher Matt Cain and third baseman Pablo Sandoval.

Cain pitched four-hit ball for seven innings, and appeared rewarded when Sandoval capped a four-hit game with a three-run homer in the eighth for a 4-1 lead. While holding Arizona to Mark Reynolds' second-inning homer, Cain walked four and struck out five and lowered his ERA from 2.37 to 2.08.

"Cain did a great job," Bochy said. "I thought we were going to win it for him, but then they stole it."

Former Arizona reliever Brandon Medders (0-1), in his third inning of work, walked Miguel Montero to start the 12th. Chris Young sacrificed Montero to second, and Felipe Lopez was walked intentionally before Augie Ojeda drew another walk to load the bases. That brought up Jackson and brought in Justin Miller, who served up Jackson's full-count hit.

Sandoval -- batting with one RBI in his first 64 at-bats of the season -- launched a 2-and-2 offering from right-hander Jon Garland high and deep into the right-field corner for his first homer of the year and first career four-hit game.

The majestic drive energized the Giants' dugout.

"It was great," Sandoval said, "but then we lost. We're out there fighting for wins."

This time the Giants spent more time fighting themselves, making the least out of a season-high 14 hits and going 2-for-15 with men in scoring position.

"We had a lot of missed opportunities," said Bochy, adding that his team's "situational hitting was off today," as was Wilson.

"Then we got the hit we were looking for all day [Sandoval's homer], and just couldn't hold it."

One of the ironies of Arizona's ninth-inning uprising was that it was only the third multiple-run frame in 71 innings off the Giants' frugal pitchers.

Nate Schierholtz, the only San Francisco position player who had not previously drawn a start, got the nod in right field on Sunday; the pinch-hit specialist went 1-for-5, the hit being a leadoff double in the seventh to set up one of the many scoring opportunities the Giants squandered.

Schierholtz had replaced Fred Lewis in the starting lineup, but even hours before Lewis' clutch pinch-hit double triggered the Giants' three-run eighth, Bochy said that the move had nothing to do with the condition of his regular left fielder's left wrist.

Lewis, who'd rolled over the wrist earlier in the season, appeared to slightly do so again on Saturday night making a diving catch of Chris Snyder's sinking liner in the second. Coincidentally, Lewis left Saturday night's game as part of a sixth-inning double-switch, and was replaced by Schierholtz.

"He's got some general soreness," Bochy said of Lewis. "He can just use a day [off]."

As for Wilson and the offense's timely hitting, their off days were not helpful.

"We won the series, but the streak is over," said Wilson. "We'll just have to start a new one now."