PHOENIX -- Arizona's Rodrigo Lopez retired 16 straight batter at one point and still lost the game.
Ryan's drive ruined an otherwise good pitching performance from Lopez, who was cruising until he allowed back-to-back singles in the seventh. Ryan homered on the first pitch he saw from Lopez with two outs in the inning.
Ryan was mired in an 0-for-16 slump before his blast.
"It's just incredibly frustrating," Ryan said. "That at-bat ... I was really just saying I would rather be late than roll over something. I was going to be aggressive with runners in scoring position, so I was just hoping he'd make a mistake and he ended up throwing a hanging slider. I was just glad I hit it."
St. Louis scored twice in the second inning off Lopez (2-5) with doubles from Matt Holliday and Skip Schumaker. Schumaker took third on the first of three Diamondbacks errors in the game, an errant pick-off attempt by Lopez that caught second baseman Kelly Johnson off guard and bounced into center field.
Yadier Molina singled to drive in Schumaker for the Cardinals' second run.
That was all starter Jaime Garcia (6-2) and the Cardinals needed. The rookie left-hander allowed one run on four hits in five innings, lowering his ERA to 1.49.
Garcia got into a bases-loaded jam in the fourth thanks to an error and two walks, but he got Lopez to ground out to end the threat.
In the fifth, after a Conor Jackson double and with two out, manager Tony LaRussa elected to intentionally walk Arizona's Mark Reynolds to put runners on first and second. Reynolds entered the game batting .212 and was second on the team in strikeouts.
The next batter, Adam LaRoche, made the Cardinals pay when he laced a double to right field to drive in Jackson.
"He actually didn't get strike one a lot," LaRussa said of Garcia. "But he made a lot of good pitches deep in the count, which is the whole key to him surviving ... the score is very misleading. It was just a weird game and fortunately we had enough things go right for us."
The Diamondbacks loaded the bases with two outs in the ninth, but could not cash in. Arizona stranded 16 runners on base, a season high, compared to just one for the Cardinals.
"They took advantage of every oppurtunity they had, and that's the difference in the game," Diamondbacks manager A.J. Hinch said. "We had a plenty of guys on base and plenty of opportunities for a key hit, and put some nice swings on some balls."
LaRussa said veteran right-hander Jeff Suppan, recently released by the Milwaukee Brewers, was to join St. Louis in Arizona late Friday night. Suppan, who helped the Cardinals win the 2006 World Series, will likely join the team's battered starting rotation. ... Diamondbacks pitcher Kris Benson, on the 15-day disabled list with a right shoulder injury, is with the team and will throw bullpen sessions next weekend. ... C Miguel Montero, who has missed 57 games with a knee injury, caught a full minor-league game Thursday. ... INF Tony Abreu, who has a left wrist injury and is also on the 15-day DL, was to start a rehabilitation assignment at Triple-A Reno on Friday.