Cameron Maybin scored the game-winner as he scampered home from third on Yonder Alonso's grounder to first.
Rivera, though, helped make that possible one batter earlier.
Maybin started the inning with what was initially ruled a groundout to second, but after a challenge by Padres manager Bud Black, it was overturned into an infield single.
After Oliver Perez struck out Will Venable, Rivera lined a double over Gerardo Parra's head in right to put runners at second and third.
"Actually, I saw the video and that was a good pitch," Perez said. "It was away. Sometimes you have to tip your cap to them because they did a pretty good job. He had a good day today. I was trying to make pitches, and they got two infield hits that I can't do anything about. That's a tough game. The pitch was away, maybe it was a little bit higher. But it wasn't a bad pitch."
The D-backs pulled the infield in, and Alonso hit a grounder that first baseman Paul Goldschmidt charged, barehanded and made a good throw home, but it was not even close.
"I thought I came in there and barehanded and threw as hard as I could," Goldschmidt said after looking at video of the play. "I was a little surprised how quickly he got down the line. I figure he had a pretty good lead. I mean we were infield in."
Not only did Maybin get a big lead, but he said he was practically running on the pitch.
"With a left-handed pitcher, I had a bigger lead," Alonso said referring to Perez. "If it was a line drive, I would have been doubled off. I was going on the swing. Yonder puts the ball in play. I figured he was going to try to hit a grounder. I broke on the swing. I didn't wait for contact."
For the first seven innings of the game, starters Wade Miley and Tyson Ross battled to a draw.
The Padres struck first in the third inning when Miley hit Jace Peterson with a pitch, and after Ross sacrificed Peterson to second, Chris Denorfia drove him home with a single to right.
The D-backs answered right back in the fourth when Goldschmidt led off with a home run, his fifth of the year to tie the score.
Later in the inning, a two-out error by shortstop Everth Cabrera and a passed ball would open the door for more Arizona runs.
After Cody Ross reached on the error and Ender Inciarte beat out an infield single, a passed ball moved both runners up, and they scored on a Tuffy Gosewisch single past a diving Cabrera to give the D-backs a 3-1 lead.
But just like in his last start against the Rockies, Miley would not be able to keep the opposition at bay.
In the bottom of the fourth, Maybin and Venable collected back-to-back two-out singles, and Rivera brought them home with a double to left to tie the game at 3.
"That one inning I gave up a run they scored three, so at least in that inning I have to shut the door," Miley said of the bottom of the fourth. "And I let them answer right back and gave them the momentum back."
The pitch to Rivera was one that Miley would like to have back, especially after disagreeing with Gosewisch on the pitch selection.
"Tuffy put down sinker and I shook to slider away," Miley said. "I had a different thought. If I execute the pitch, if I thow it down and away maybe I get away with it, but the right pitch is probably the sinker down and away."