Paul Goldschmidt hit a three-run homer, Zack Greinke pitched effectively into the seventh inning and the Arizona Diamondbacks ended a four-game losing streak with a 4-2 win over the St. Louis Cardinals on Tuesday night.

Goldschmidt followed a four-hit night Monday with a three-run homer off Jack Flaherty (3-4) in the fifth inning. The NL player of the month for June, Goldschmidt is hitting .413 with 11 homers and 28 RBIs his past 26 games.

Greinke (9-5) gave up two runs in the second inning to end his 13-inning scoreless streak but was otherwise sharp in winning his fourth straight game. Yoshihisa Hirano needed one pitch to get a groundout with the bases loaded in the seventh and extend his team record with a 26th straight scoreless appearance.

Brad Boxberger worked around a walk in the ninth for his 20th save in 24 chances.

Greinke entered Tuesday's game with the 13-inning scoreless streak after tossing seven scoreless innings against Miami his last start. His streak lasted one more inning; the Cardinals scored two runs in the second inning on Yairo Munoz's single and Kolten Wong's sacrifice fly.

Greinke shook off the shaky second by mixing his pitches well, keeping the Cardinals off-balance with low-90s fastballs and looping curves that dipped to 63 mph. He was lifted with two outs in the seventh inning after giving up consecutive hits, allowing two runs on seven hits and four strikeouts.

Flaherty allowed four runs on six hits in six innings in a loss to Cleveland his last start. He was sharp after giving up David Peralta's run-scoring single in the first inning, retiring 10 straight batters.

Flaherty ran into trouble in the fifth inning, giving up a double and hitting a batter before Goldschmidt lifted a three-run homer just over the wall in right to put Arizona up 4-2.

Flaherty allowed four runs on four hits and struck out seven in six innings.

TRAINER'S TABLE

Cardinals: SS Paul DeJong (broken left hand) went 0 for 4 for Triple-A Memphis on Monday night, his third rehab game with the Redbirds.

Diamondbacks: RHP Randall Delgado (strained left oblique) allowed a run on three hits in an inning for Triple-A Reno Monday night in a rehab appearance. ... OF Steven Souza Jr. went 1 for 4 with a solo homer for the Aces as he works back from a strained right pectoral.

UP NEXT

Diamondbacks LHP Patrick Corbin has allowed a run in 13 innings his past two starts heading into Wednesday's game against the Cardinals. St. Louis sends out RHP Miles Mikolas, who lost his last start despite allowing a run in 6 2/3 innings against Atlanta.