ST. LOUIS (AP) Adam Wainwright tried his best to keep up with Cardinals teammates Carlos Martinez and Michael Wacha. The veteran right-hander simply came up short.

Matt Carpenter homered and Wainwright turned in his second successive strong outing to lead St. Louis over the San Francisco Giants 8-3 on Sunday, snapping a four-game skid.

Wainwright (4-3) allowed one run and five hits in 6 1/3 innings. Martinez threw nine shutout innings Saturday, and Wacha pitched six scoreless innings Friday.

''I blew it,'' Wainwright joked.

But he was plenty effective.

Wainwright set down the side in order three times and retired seven in a row during one stretch. He struck out six, walked three and even hit an RBI double in the sixth.

''I've just been feeding off our other starters,'' Wainwright said. ''I wanted to keep that momentum going.''

Randal Grichuk drove in four runs for St. Louis, which handed San Francisco only its second loss in nine games.

Wainwright tossed seven sharp innings in a 5-0 win over the Chicago Cubs last Sunday. Before that, he had given up four earned runs in each of his previous three starts.

''I've made good adjustments and I feel like I'm in a good place,'' said Wainwright, who has permitted one run in his last 13 1/3 innings.

He improved to 28-14 in May, his most wins in any month.

''I feel like he's back to normal,'' Grichuk said. ''He looks great out there and the numbers the last few games really show it.''

Carpenter hit a two-run homer off Matt Cain (3-2) in the fifth. Cain gave up seven runs and nine hits in 5 1/3 innings. He is 0-4 in six regular-season starts at Busch Stadium.

''I've got all kinds of answers that would be funny,'' Cain said. ''But there's no real reason that my record looks like that here. I just don't know why.''

Cain is 3-0 with a 1.19 ERA at home this season, but 0-2 with an 8.28 mark on the road.

San Francisco manager Bruce Bochy was surprised to see Cain struggle. Cain had given up two earned runs or fewer in six of his last seven starts.

''He was just behind more than he's normally been this year,'' Bochy said. ''You could see, he wasn't as sharp today.''

Grichuk slammed a three-run double in the second to highlight a four-run outburst. He doubled home another run in the eighth.

''I feel like I've had a bunch of balls that have flown out at the track the last couple weeks,'' Grichuk said. ''It was good to see them fall for a change.''

Brandon Crawford and Eduardo Nunez hit back-to-back homers in the eighth for the Giants, who were looking for their first three-game sweep on the road this season.

The Cardinals lost five of eight games on their homestand, including three one-run defeats and a 3-1 setback in 13 innings.

''It certainly could have been much better,'' manager Mike Matheny said. ''Some late lapses really hurt us.''

YADI ON A ROLL

St. Louis catcher Yadier Molina extended his hitting streak to 11 games with a single in the third. He has reached safely in his last 16 games.

JHONNY IS BACK

Cardinals INF Jhonny Peralta is 4 for 5 since returning from the disabled list Friday. He missed 26 games with an upper respiratory ailment. Peralta singled twice and walked in his first three trips to the plate Sunday.

TRAINER'S ROOM

Giants: C Buster Posey was given the day off after catching all 13 innings of a 3-1 win over St. Louis on Saturday.

Cardinals: 2B Kolten Wong did not start due to a stiff elbow. He is day to day.

UP NEXT

Giants: LHP Ty Blach (1-2, 4.15 ERA) faces Chicago Cubs RHP John Lackey (4-3, 4.37) on Monday night in the opener of a four-game series at Wrigley Field. Blach has replaced injured ace Madison Bumgarner in the rotation.

Cardinals: RHP Lance Lynn (4-2, 2.78 ERA) opposes Dodgers ace Clayton Kershaw (7-2, 2.15) in the first of a three-game set Tuesday night at Los Angeles. Lynn has given up two runs or fewer in five of eight starts this season.

Copyright 2017 by Associated Press. Any commercial use or distribution without the express written consent of Associated Press is strictly prohibited.