PHOENIX — The Los Angeles Dodgers rallied from six runs down, only to lose in extra innings Sunday night.

No worries. The Dodgers can do plenty to control their postseason fate starting Monday in a series against the Giants.

Brandon Drury singled with two outs in the 12th inning to score Paul Goldschmidt, lifting the Arizona Diamondbacks over the Dodgers 10-9.

Los Angeles maintained its five-game lead in the NL West over San Francisco after the Giants lost earlier Sunday. Los Angeles heads home following a 5-5 trip to host the Giants for a three-game series.

“Our guys have done a nice job of not letting this road trip get to us and tax us too much and fatigue us mentally,” manager Dave Roberts said. “It’s going to be nice to get in front of 40,000 people who are cheering for you. There’s going to be a lot of excitement, and we’re looking forward to playing well.”

Drury had four hits, including a home run, and got his chance in the 12th after the Dodgers intentionally walked Jake Lamb. Ross Stripling (4-8) got the loss.

Goldschmidt stretched a base hit into a double with two outs before Lamb’s walk.

“A credit to Goldschmidt,” Stripling said. “Oh for 5 and he’s still running out singles up the middle and he turns it into a double. And then we intentionally walk the lefty to get to Drury, who’s had a good day. Get 1-1 and try to throw a heater up and it just kind of stays middle-middle.

“We’re a resilient team,” Stripling added. “We saw San Francisco was down and had a chance to get a game. We just weren’t able to pull through today.”

The game lasted 4 hours, 29 minutes. Matt Koch (1-0) won for Arizona.

Howie Kendrick broke a 7-all tie in the eighth with a two-out, two-run double, but Chris Owings hit a two-run home run with two outs in the eighth to make it 9-9.

The Diamondbacks loaded the bases with walks in the eighth and had a chance to regain the lead after blowing a 6-0 advantage, but Mitch Haniger grounded out sharply to third base to end the inning.

Both teams had two runners on base in the ninth but couldn’t deliver. Owings struck out against Stripling with the potential winning run at third base in the ninth.

Adrian Gonzalez’s pinch-hit double in the sixth with two outs and the bases loaded tied it at 7, part of a six-run inning for Los Angeles.

Haniger had three hits, including a two-run homer.

Starter Robbie Ray struck out eight of the first 14 batters and did not allow a hit until the fifth, when Kike Hernandez homered with two outs. Ray lasted 5 2/3 innings and allowed five runs on five hits, eight strikeouts and a pair of walks.

Diamondbacks reliever Randall Delgado walked the bases loaded in the sixth, then walked Austin Barnes to make the score 7-4. Gonzalez lined a double toward the right-field corner off Edwin Escobar, driving in three of the Dodgers’ six runs in the inning.

It was Gonzalez’s first pinch hit since Sept. 25, 2013, and the large contingent of Dodgers fans roared.

The Diamondbacks tagged starter Jose De Leon for six runs, four of those earned, in 3 2/3 innings. De Leon, a rookie who’d won his first two starts, gave up seven hits.

“I made mistakes early and they were making me pay,” De Leon said.

PEDERSON TOSSED

Dodgers center fielder Joc Pederson was ejected for arguing a called third strike in the eighth inning, the fifth ejection for the team this season and his first.

TRAINER’S ROOM

Dodgers: Roberts said pitcher Scott Kazmir developed a blister while throwing a simulated game Sunday. He’s been on the disabled list with a neck problem since Aug. 23. … Pitcher Alex Wood, normally a starter, will be activated from the 60-day disabled list on Monday, and Roberts’ plan is to start him out of the bullpen for an inning. It figures to be Wood’s role for however long the Dodgers’ season lasts.

UP NEXT

Dodgers: LHP Clayton Kershaw (11-3, 1.81) gets the start against Giants ace Madison Bumgarner on Monday night in Los Angeles, the start of a key series between the two rivals. Kershaw has had two starts since coming off the 60-day disabled list earlier this month. “You look at the way our rotation is configured, the same way the Giants’ is configured,” Roberts said. “It gives the best chance against those guys and I think they feel the same about playing against us.”