Alex Wood pitched seven strong innings of three-hit ball, and the San Francisco Giants beat the St. Louis Cardinals 5-2 on Wednesday night.

Darin Ruf homered for San Francisco. Mike Yastrzemski and Donovan Solano both doubled in runs as the Giants avoided a three-game sweep.

San Francisco had lost six of nine but still owns the best record in the majors at 54-32 with three games left before the All-Star break.

"(Wood) takes the responsibility of pitching well when we’re not at our best very seriously," Giants manager Gabe Kapler said. "What was different in tonight’s game was he had all of his pitches working well. He had good command and control of all three of his pitches and mixed it up well. That was a pretty gritty and tough outing from him. It was exactly what we needed."

Dylan Carson had two hits for St. Louis.

CLICK HERE FOR MORE SPORTS COVERAGE ON FOXNEWS.COM

Wood (8-3) set down 19 of 22 after allowing Nolan Arenado’s two-out RBI double in the first. The Giants lefty had six strikeouts and two walks and won for the first time in four career starts against the Cardinals.

"I thought we had a good plan going in," Wood said. "I felt like I commanded my fastball really well and stuck the slider. Good overall night, that’s for sure. Games like that are important. I was happy to come out and do my job tonight."

Tyler Rogers retired three batters. Jake McGee pitched the ninth for his 17th save.

St. Louis starter Johan Oviedo (0-5) couldn’t overcome a shaky start. Eight of Oviedo’s first nine pitches were balls and the Giants first run came when the right-hander hit Jason Vosler with the bases loaded.

Oviedo, who is winless in his first 16 career starts, allowed two runs and three hits in four innings.

"You’re seeing a guy that’s still working on his craft at the big league level," Cardinals manager Mike Shildt said. "I think he’s really close. Patience is required but the payoff is going to be big."

MIND GAMES

Oviedo thought the Giants were stealing signs and got into an exchange with Yastrzemski, who was at second base with Wilmer Flores batting.

"I thought they were robbing the signs," Oviedo said. "The way (Flores) was taking my pitches I was like, ’OK, he’s gotta have (a sign). That’s what I thought."

Yastrzemski called it gamesmanship but denied stealing signs.

"Part of the game is the mental side," Yastrzemski said. "Whether teams are paranoid or think we’re doing things we’re not, it’s a distraction. They changed their signs four or five times. I had no clue."

WILD PITCH

Cardinals reliever John Gant nearly threw a ball over the protective netting behind home plate after a late timeout was granted by home plate umpire Roberto Ortiz. Wood was at the plate and stepped out of the batters box just as Gant began his delivery, causing the St. Louis pitcher to sail the ball near the top of the netting.

GIANTS MOURN PASSING OF EXEC

A moment of silence was held before the game for Giants Director of Dominican Republic Operations Pablo Peguero, who passed away Wednesday morning at his home in Santo Domingo. The 68-year-old Peguero was in his 18th season with the club. He previously worked with the Dodgers and was general manager of the Dominican Republic Olympic Team for the 1999 PanAm Games.

TRAINER’S ROOM

Cardinals: RHP Carlos Martínez was placed on the 10-day Injured List because of what Shildt termed a torn ligament in Martínez’s right thumb, an injury the pitcher suffered while batting during Sunday’s loss in Colorado. "It’s not great," Shildt said. "It’s certainly going to be something that’s going to impact him for some time. I don’t expect him back in our rotation in the very near future." OF Lars Nootbaar was recalled from Triple-A Memphis.

Giants: Leadoff hitter LaMonte Wade Jr. came out of the game with a left hand strain. … Buster Posey sat out his third consecutive game with a bruised left thumb.

UP NEXT

Cardinals: Following an off day, LHP Wade LeBlanc (0-1, 4.24 ERA) faces the Cubs at Wrigley Field on Friday afternoon. LeBlanc is making his first start against Chicago since 2013 when he was with the Marlins.

Giants: RHP Logan Webb (4-3, 3.86) will come off the IL to start against Washington on Friday. Webb has been out since June 3 with a right shoulder strain.