NEW YORK — Dellin Betances gave up a run, so did Andrew Miller and Aroldis Chapman almost got nicked, too. A surprising sequence for the Yankees' vaunted bullpen trio.

But Giants shortstop Brandon Crawford put on the most startling performance Friday night — the Gold Glover threw away three balls, all by himself.

Crawford committed three errors for the first time in his career, making a wild toss in the eighth inning that gave New York a 3-2 win and sent San Francisco to its season-worst sixth straight loss.

"We'll take it any way we can get it," said Chase Headley, who slid home just in time with the go-ahead run. "You've got to be opportunistic.

"We're fighting for our life right now," he said.

The Yankees won for the fifth time in six games, trying to improve their playoff possibilities. Joe Girardi managed as if it was a post-season game, making three defensive replacements in the late innings.

"These are tough losses if you lose," he said, adding, "but that's not the case, don't have to worry about it."

The Giants held the best record in the majors at the All-Star break, but haven't won since. They also lost catcher Buster Posey, who fouled a ball off his right foot and left with a bruise. X-rays were negative and he was listed as day to day.

"We hit a couple of balls hard, but we didn't get a break," Giants manager Bruce Bochy said. "And that's the way it goes. When you're in winning streaks, everything goes right. Right now, it's not going well for us. But still, you make your breaks. We've got to tighten up and play crisper ball."

Said Crawford: "Three errors? Nah, it's not happened before.

"Just kind of three kind of weird plays, all different kind of throws that happened to get away from me," he said.

Masahiro Tanaka shut out San Francisco for six innings, giving up four singles. Giants ace Madison Bumgarner went seven innings, allowing two runs.

The Giants nicked Betances in the seventh, pulling within 2-1 on a walk, a double by Denard Span and a wild pitch. That ended a streak of 31 scoreless innings by Yankees relievers.

A double by Giants pinch-hitter Mac Williamson off Miller (6-1) tied it in the eighth. For the most part, the back end of the Yankees' bullpen has been automatic in putting up zeros.

"You don't see it very often. So when it happens, you're shocked," Girardi said.

But the Yankees bounced back, and didn't need to hit the ball hard to do it.

Headley opened the eighth with a swinging bunt for a single off Josh Osich (1-2) and Mark Teixeira walked. Austin Romine followed with a grounder to Crawford, who tagged second, spun around and made a hard, high throw that glanced off the glove of first baseman Brandon Belt.

Headley kept running and beat Belt's throw home. Crawford won his first Gold Glove last season.

"Just trying to anticipate a bad throw," Headley said. "I felt like it rolled far enough away."

Chapman closed in the ninth for his 20th save in 21 chances. He worked around a leadoff double by Gregor Blanco.

A spirited crowd of 45,304 also included lots of Giants fans, and the rival rooters spent much of the game loudly cheering, often at the same time. There was a truce when a marriage proposal was shown on the scoreboard in-between innings — he wore a Giants hat, she wore a Yankees cap and said yes to a ring.

Carlos Beltran hit an RBI single and reached base four times for New York, and also contributed on defence. The 39-year-old right fielder unleashed a perfect throw home to nail Blanco and later made a running grab to rob Crawford of extra bases.

COMFORTABLE CASTRO

Starlin Castro hit an RBI double in the first inning and later singled twice against Bumgarner. Castro is 14 for 27 (.519) lifetime against the star lefty.

INTERLEAGUE WOES

The Yankees are just 4-7 in interleague play, with nine games left. The Giants are 6-9 vs. AL teams.

TRAINER'S ROOM

Giants: OF Hunter Pence (hamstring) was set to play for Triple-A Sacramento, but INF Joe Panik (concussion) was out of the lineup for the second straight day.

UP NEXT

Giants: RHP Jeff Samardzija (9-5, 4.05) walked a season-high four in his last start vs. San Diego. He is 0-1 with a 6.92 ERA in three career games against the Yankees.

Yankees: RHP Ivan Nova (7-5, 4.92) pitched a shutout in 2013 in his only career start vs. the Giants. He has won his last two starts overall.