After allowing an unearned run in the eighth, Lopez faced Goldschmidt with two on and two out and the slugger standing at the plate representing the go-ahead run. But after a five-pitch at-bat, Lopez got Goldschmidt to ground out to third to end the threat.
"I think Paul is the right guy in the right spot at any time, any situation when the game's on the line," Diamondbacks manager Torey Lovullo said. "We made pitches when we had to. We executed, and got the big outs and that's the name of the game."
Goldschmidt went 0 for 4 with two strikeouts in his first game against Arizona since being traded from the Diamondbacks to the Cardinals last December.
"You understand where the game is," Goldschmidt said. "I was just trying to get on base. If I could just get (Matt Carpenter) up there who knows what happens? You can't force it. In those situations you try not to do too much and I think over the course of my career I've done a good job of not getting too locked into a situation. Just try to take each at bat, each pitch within itself."
Ray (7-6) struck out eight and walked two as the Diamondbacks won their fourth straight. He won back-to-back road starts for the first time since May 3-8 and improved to 9-0 when starting on six-plus days of rest dating back to 2015.
Ray also improved to 2-1 with a 1.41 ERA in four career starts at Busch Stadium.
"I'm just getting ahead of guys, pounding the zone, and when I get ahead of guys putting them away, not letting them stay around too long," Ray said. "I felt like I managed the game, managed my pitch count early in this game, got a lot of weak contact. Even with guys on base I was able to get some weak contact, ground balls, pop ups. "
Lamb's second homer of the season off Andrew Miller (3-4) broke a 1-1 tie in the seventh to help send the Cardinals to their third straight loss. Lamb now has two home runs in the last six days.
"I've faced him (Miller) a few times and he's completely dominated me," Lamb said. "He's been doing it for a while to the whole league. To get a swing off like that felt good, especially in that situation."
Marte's two-run shot in the eighth extended the lead and proved to be the game-winning RBI. He extended his hit safely streak to six games.
Christian Walker sent a 92 mph fastball into the left field bullpen to give the Diamondbacks a 1-0 lead in the fourth. Walker has hit in six straight games and has four homers and 11 RBI during that span.
Daniel Ponce de Leon, who was named the starter by the Cardinals earlier in the day for an ailing Adam Wainwright, gave up one run over a season-high 6 2/3 innings. He allowed three hits, struck out seven and didn't walk a batter.
Matt Wieters tied the game for the Cardinals with an opposite-field home run in the fifth. It was his third homer in his last six games.
Wainwright was pulled from the starting lineup due to back spasms. He wasn't put on the Injured List and Shildt said he could make his next start as early as Sunday.
"I don't think he's going to skip a turn," Shildt said. "I think you could see him potentially go in a couple of days."
Diamondbacks: RHP Taylor Clark (lower back inflammation) will make a rehab start at High-A Visalia on Saturday and will throw 70 to 75 pitches. OF David Peralta (right AC joint inflammation) hopes to resume baseball activities on Monday.
Cardinals: C Yadier Molina (right thumb strain) was placed on the Injured List on Thursday retroactive to July 8.
Diamondbacks: RHP Merrill Kelly (7-8, 4.03 ERA) will get the start in the second of a three-game series at St. Louis on Saturday night. He is 2-1 with a 2.45 ERA in his last four road starts.
Cardinals: RHP Dakota Hudson (7-4, 3.51 ERA) will make his first career appearance against Arizona. He earned the win, giving up three runs in five innings in his last start against San Francisco on July 5.
More AP MLB: https://apnews.com/MLB and https://twitter.com/AP-Sports
Bomani wants to see the Yankees throw money at Cole
Bomani Jones and Pablo Torre both want to see the Yankees sign Gerrit Cole to a record-setting deal.
Yankees GM rappels building, gets fan's message on Gerrit Cole
Brian Cashman saw a message taped to a 10th-floor window while prepping for a festival in Connecticut. "Please sign Gerrit Cole," it said. The GM's response: "I'm open to do clearly whatever, as always, is important for the Yankees."
Rays' Blake Snell strongly reacts to Tommy Pham trade on Twitch
Rays pitcher Blake Snell apologized for his reaction -- captured during a livestream on Twitch -- to news that teammate Tommy Pham was traded to San Diego.
What's next for the teams that lose the Gerrit Cole sweepstakes?
One team will land the best pitcher on the planet. The rest of his suitors? They'll have to scramble.
Source: Nationals agree to deal with World Series hero Howie Kendrick
Howie Kendrick, who capped the Nationals' improbable run to their first World Series title last season with a Game 7 home run, has reached an agreement on a one-year, $6.25 million deal to return to Washington, a source told ESPN's Jeff Passan on Friday.
Win-now Padres pay steep price for Tommy Pham
San Diego took another step toward contending in 2020 by adding the outfielder but shipped one of its best prospects to Tampa Bay in the process.