Evan Longoria homered with one out in the seventh inning to break up Jack Flaherty's bid for a no-hitter, and the Giants held on to beat the Cardinals 1-0 on Sunday.
San Francisco won for the seventh time in nine games despite getting only two hits off Flaherty. Alex Dickerson followed Longoria's drive with a bloop single to left that glanced off the glove of All-Star shortstop Paul DeJong.
Flaherty was masterful before Longoria's home run. The 23-year-old retired his first 12 batters before walking Alex Dickerson leading off the fifth. He struck out two of the next three and got Kevin Pillar to foul out.
But the Cardinals couldn't muster much offensively and Flaherty became the latest St. Louis pitcher to come up short in a no-hit bid. Adam Wainwright twice had no-hitters broken up in the sixth inning this season, against Cincinnati on April 13 and the Cubs on June 2.
Flaherty (4-6) struck out six and allowed two hits in seven innings.
Jeff Samardzija (6-7) pitched seven scoreless innings and allowed four hits to beat the Cardinals for the first time in four career starts at Oracle Park.
Samardzija took a no-hitter into the fifth, pitched out of a jam in the sixth after allowing a one-out double, then got Matt Wieters to fly out with two on and two out in the seventh.
Sam Dyson retired three batters. All-Star closer Will Smith pitched the ninth and is 23-for-23 in save opportunities.
Yairo Munoz had two hits for St. Louis. The Cardinals finished 4-5 on their road trip and head into the All-Star break two games behind first-place Chicago in the NL Central.