SAN DIEGO -- After the San Diego Padres lost four straight games overall as well as their first four home games at Petco Park, rookie manager Andy Green was looking for anything to give his struggling club a boost.
Left fielder Melvin Upton Jr. provided that boost Saturday night.
Upton hit a two-out, two-run, walk-off homer in the bottom of the 14th inning to give the Padres a 5-3 victory over the Arizona Diamondbacks at Petco Park.
"Games like this have a carry-over," Green said. "They are tough to lose and carry a bonus when you win. We needed an emotional boost. It's a great win for us."
Upton's drive to straightaway center off Ruddy De La Rosa cleared leaping of Diamondbacks center fielder David Peralta.
"I wasn't sure at this ballpark if that was out," Upton said of his second homer of the season. "Peralta deked me pretty good. I was running hard. Then, when I saw his back against the wall, I felt good."
"That was kind of close," Peralta said. "It was a deep fly. I didn't know it was gone. That ball was way high and was carrying, carrying, carrying. I was trying to make a play, but I couldn't."
The Padres opened the season by setting a major league record with three straight shutout losses to the Los Angeles Dodgers at Petco Park and had scored only five runs in 49 innings at home before Upton's blast.
Wil Myers started the Padres' winning rally when he dropped a single into right against De La Rosa - Arizona's ninth pitcher -- for his fourth hit of the game. De La Rosa rallied by striking out Travis Jankowski and Adam Rosales to bring up Upton, who had two singles in his first six at-bats.
The Padres had built a 3-0 lead behind right-handed starter Andrew Cashner before the Diamondbacks rallied with single runs in the fifth, seventh and eighth to tie the score.
Cashner, who is still looking for his first win this season after posting a 6-16 record in 2015, allowed one run, four hits and two walks with five strikeouts in six innings.
Padres relievers Kevin Quackenbush and Brandon Maurer each gave up a single run with the help, respectively, of an error and a two-out wild pitch.
In the seventh, Arizona left fielder Yasmany Tomas hit a one-out double off Quackenbush and advanced to third when Upton misplayed the ball in left center. Tomas scored the unearned run on a sacrifice fly by right fielder Brandon Drury.
Pinch-hitter Rickie Weeks opened the eighth with a double off Maurer, reached third on a groundout and scored on a two-out wild pitch by Maurer, who had frozen Weeks at third with a strikeout of Peralta.
Both teams stranded the winning run in scoring position in the ninth and 10th innings.
Defensive plays by Jankowski in right and Myers at first stopped the Diamondbacks in the 11th.
Jankowski made a sensational headfirst diving catch in short right-center of a Nick Ahmed line drive to open the inning and Myers made a diving stop and a flip to first to get Jean Segura for the third out with a runner on.
Left-handed Padres reliever Brad Hand kept the score tied in the top of the 12th when he struck out three Diamondbacks around two walks.
In the bottom of the 12th, the Padres had runners on first and second with one out when Diamondbacks closer Brad Ziegler struck out Jankowski and Rosales.
After Padres left-hander Ryan Buchter struck out all three Diamondbacks he faced in the top of the 13th, the Padres loaded the bases with one out in the bottom of the inning. But Ziegler struck out pitcher Colin Rea, who was pinch-hitting, then retired Jay on a fly to left.
The Padres took a 2-0 lead in the second while the Diamondbacks were losing starting pitcher Shelby Miller to a freak injury.
Upton started the rally with a one-out single, stole second base and scored when Alexei Ramirez lined a two-out single to center. The shortstop reached third when the ball skipped past Arizona center fielder Socrates Brito for an error.
Miller then walked Padres second baseman Alexi Amarista to pitch to Cashner.
On his 1-and-1 pitch to Cashner, Miller's right hand hit the ground on his follow through. Miller suffered cuts to both knuckles of his right index finger, which was visibly bleeding.
"It was just some poor mechanics," Miller said. "I just sort of fell off the side of the mound and my hand hit the ground a couple of times."
Despite two visits from the Arizona trainer, Miller continued in the game and walked Cashner before issuing a full-count, base-loaded walk to slumping center fielder Jon Jay to force in the second run of the inning. The trainer had checked Miller's right hand a second time after the 2-and-0 pitch to Jay.
Miller departed after walking Jay, who had been hitless in 15 straight at-bats. Former Padres farmhand Matt Buschmann entered the game and struck out Myers to end the threat.
But right fielder Matt Kemp opened the third with the first home run hit by the Padres at Petco Park this season, the 385-foot line drive off Buschmann to make it 3-0.
The Diamondbacks got on the board in the top of the fifth. Left fielder Yasmany Tomas singled with one out and moved to third when Drury doubled over Jay's head in center. Tomas scored on a grounder to second by second baseman Segura.
NOTES: At different times during Friday night's game, the Padres had two players -- CF Jon Jay and 1B Wil Myers -- who were both in 0-for-14 streaks. RF Matt Kemp was in a 2-for-19 slump, 2B Cory Spangenberg was in a 2-for-18 run and C Derek Norris was 1-for-10. ... Saturday marked only the third time this season that the Diamondbacks hit the pitcher in the ninth spot in the order. Arizona manager Chip Hale said he was doing it to kick-start the offense. ... Diamondbacks RHP Daniel Hudson has held the Padres scoreless in seven straight outings at Petco Park. ... C Austin Allen is hitting .636 (21-for-33) for Class A Fort Wayne of the Midwest League. Allen's batting average has fallen each of the last three days, although he got two hits in each game. ... Myers has struck out at least once in all 12 games played by the Padres this season.