PHOENIX — The Arizona Diamondbacks did some damage against Giants ace Madison Bumgarner, but couldn’t protect a three-run lead and lost 7-6 in 12 innings Friday night.

Pinch-hitter Kelby Tomlinson’s one-out single in the 12th drove in Brandon Belt with the go-ahead run, and the Diamondbacks were unable to extend the game any further despite putting two runners on in the bottom of the inning.

“They are playing for their lives over there. They know it,” Arizona manager Chip Hale said. “I thought our guys matched it. It just didn’t come out our way.”

Giants reliever Cory Gearrin got one out before being moved to left field for one batter so lefty Javier Lopez could face left-handed hitter Jake Lamb, who tied the score at 6 with a pinch-hit homer in the 10th.

Gearrin was then put back on the mound by manager Bruce Bochy to finish the game for his third save. With two runners on, Gearrin struck out Welington Castillo looking for the second out on a 3-2 pitch, and Castillo was ejected for arguing.

“It’s a ball. I cannot swing at that pitch. I just said it,” Castillo said about his conversation with plate umpire Dale Scott. “It would have been a different game if I had walked.”

Yasmany Tomas grounded out to end it.

Joe Nathan (2-0) escaped an 11th-inning jam in a game that lasted 5 hours, 23 minutes.

Dominic Leone (0-1) took the loss.

Arizona used 26 players, including 12 pitchers — both franchise records.

Gearrin became the first Giants pitcher to play the field since 2007.

San Francisco maintained its half-game lead over the Mets for the top NL wild card, with St. Louis just a half-game behind New York. The Giants also moved within four games of the first-place Dodgers in the NL West.

Hunter Pence gave the Giants a 6-5 lead in the top of the 10th, scoring on Enrique Burgos’ wild pitch. Pence had four hits and made a key defensive play in right field.

The Giants turned to Santiago Casilla to try to close it out, but Lamb extended the game with a solo homer in the bottom of the 10th.

The Diamondbacks made it 5-all in the seventh when Giants center fielder Denard Span dropped Chris Owings’ long fly for a three-base error. Pinch-runner Socrates Brito scored on the play, but Owings was thrown out trying to score.

That was after Angel Pagan’s solo home run gave the Giants a 5-4 lead.

Pence took an extra-base hit away from Mitch Haniger in the bottom of the ninth with a sliding catch in the right-field corner.

Bumgarner was briefly in line for his 100th career win, but ended up tossing six innings and allowing four runs on six hits with nine strikeouts and a walk in a no-decision.

The Diamondbacks built a 4-1 lead against Bumgarner with two-run homers by Brandon Drury in the second inning and Kyle Jensen in the third, Jensen’s first major league home run.

Jensen, called up from Triple-A Reno on Sept. 3, entered as an injury replacement for A.J. Pollock in the top of the second.

Diamondbacks starter Rubby De La Rosa was on a pitch limit in his first start since late May. He was activated from the 60-day disabled list before the game after coming back from a right elbow injury and threw 43 pitches before leaving for a pinch hitter.

De La Rosa struck out three in two innings but gave up a run in the second on an infield single, two walks and Eduardo Nunez’s sacrifice fly.

“We capitalized when we had to. A lot of missed opportunities on both sides,” Bumgarner said. “We found a way to get it done and it was a big win for us.”

HOWLIN’ WITH THE DIAMONDBACKS

The Diamondbacks celebrated the upcoming season for the NHL’s Arizona Coyotes, the team’s 20th. Coyotes veterans Shane Doan and Mike Smith took batting practice with the Diamondbacks. Doan, who has been with the club since it moved to Arizona from Winnipeg, threw out the ceremonial first pitch. The Coyotes open training camp next week.

Diamondbacks home runs brought the playing of the Coyotes’ goal song that is heard at Gila River Arena.

TRAINER’S ROOM

Giants: Nunez was slow running up the line on a sixth-inning single, but after being checked by a trainer he stayed in the game.

Diamondbacks: Pollock left in the bottom of the first after appearing to get injured running out a fly ball. Pollock only recently returned from his season-long rehabilitation of a broken elbow. Hale gave no update on Pollock’s status. … C Chris Herrmann broke his hand while sliding, Hale said. … With De La Rosa activated, infielder Nick Ahmed (hip) was transferred to the 60-day disabled list.

UP NEXT

Giants: RHP Johnny Cueto (14-5) faces the Diamondbacks on Saturday for the fifth time this season. He is 2-2 in the previous four starts.

Diamondbacks: RHP Archie Bradley (6-8) has two wins in his last three starts.