NEW YORK -- Mac Williamson homered in the fifth inning and hit a tiebreaking single in the 12th, lifting San Francisco over the New York Yankees 2-1 Saturday for the Giants' first victory since the All-Star break.
NL West-leading San Francisco had lost a season-high six straight games and had held just one lead since the break: when Buster Posey hit a go-ahead home run leading off the 10th inning at San Diego on July 16 only to have the Padres rally for a pair of runs in the bottom half against Santiago Casilla.
Williamson, whose fourth-inning error allowed the Yankees' run, began the comeback when he connected off Ivan Nova leading off the fifth.
Trevor Brown hit an opposite-field double to right off Anthony Swarzak (1-1) leading off the 12th, and Williamson singled up the middle with one out, just past the glove of diving shortstop Didi Gregorius. San Francisco was 0 for 10 with runners in scoring position, dropping to 7 for 64 (.111) since the All-Star break, before Williamson's single.
Cheered on by hundreds of orange-clad fans in the Giants' old hometown, San Francisco escaped a bases-loaded, one-out jam in the 10th when Casilla (2-3) retired Brian McCann on a shallow flyout and Starlin Castro on a foulout. Hunter Strickland pitched a perfect 12th for his second save.
San Francisco had joined the 1991 Los Angeles Dodgers as the only teams to enter the break in first place, then lose its first six games of the second half, according to the Elias Sports Bureau. And after making four errors in the series opener, San Francisco had two more.
Jeff Samardzija had been listed as San Francisco's starter, but manager Bruce Bochy said his intent all along was to start Johnny Cueto and attributed the mixup to a failure to inform his media relations staff.
In a late-afternoon start on a 93-degree day, Cueto struggled with deep counts but allowed just an unearned run and six hits in six innings. He struck out nine -- including five in a row -- walked none and threw 117 pitches, two shy of his season high.
Nova gave up one run and six hits in seven innings.
Andrew Miller struck out two in a perfect eighth, and Aroldis Chapman threw a season-high 36 pitches over two innings, working around pinch-hitter Grant Green's leadoff double in the 10th and striking out three.
Dellin Betances walked Angel Pagan leading off the 11th, and Pagan stole second and took third on a groundout. With catcher Brian McCann signaling for an intentional walk, Betances threw his first pitch to Brandon Crawford to the backstop. But Pagan held at third to Bochy's dismay. Betances then pitched to Crawford and retired him on a grounder.
New York (49-48) dropped to 5-4 on its 10-game homestand, as players attempt to persuade management not to deal veterans before the Aug. 1 deadline for trades without waivers. The Yankees are 19-2 when using their No Runs DMC bullpen trio.
Brett Gardner and the Yankees made sparkling defensive plays that ended each of the first two innings.
Posey flied to right with runners at the corners and one out in the first, and Pagan held at third in respect of Aaron Hicks' strong arm. Crawford then sliced a liner to left, and Gardner stuck out his right arm to make a sliding catch.
With a runner at first and two out in the second, Ramiro Pena lofted a double to the left-center gap. Gardner grabbed the wall with his bare hand and, without setting, made a one-hop throw to Gregorius about 30 feet onto the outfield grass. The shortstop then threw to McCann at the plate.
New York went ahead in the fourth after Gregorius reached on an infield single leading off. Mark Teixeira, in a 1-for-15 slide and dropped to seventh in the batting order for only the third time since 2004, singled to right. Williamson allowed the ball to kick off his glove for an error, and Gregorius came all the way around, tumbling across the plate.
Giants: OF Hunter Pence (hamstring) was to play six innings Saturday for Triple-A Sacramento, seven innings Sunday and then take a day off. ... INF Joe Panik (concussion), who hasn't played for the Giants since June 27, played for Sacramento on Tuesday and Wednesday but is sidelined again for a couple more days. ... INF Matt Duffy, out since June 19 because of a strained left Achilles tendon, is running 60-yard sprints at 75 percent. ... RHP Cory Gearrin, who hadn't played since July 5 because of a strained right shoulder, is to pitch to hitters Sunday.
Samardzija (9-5) walked a season-high four in his last start vs. San Diego and is 0-1 with a 6.92 ERA in three career games against the Yankees. Nathan Eovaldi (8-6) starts for the Yankees after beating Baltimore on Tuesday in his rotation return, ending a six-start winless streak.