NEW YORK — The Yankees’ normally steady bullpen wasted a chance to clinch New York’s first playoff berth in three years when Dellin Betances gave up a tying homer and Andrew Bailey allowed the go-ahead hit in Boston’s 9-5, 11-inning victory Wednesday night.

After losses in the first two games of the four-game series and with the chance to wrap up a wild-card berth, the Yankees rallied from a 3-0 deficit. Alex Rodriguez’s first homer in two weeks gave them a 5-4 lead in the sixth.

But on a night when Masahiro Tanaka struggled early in his return from a hamstring injury, the Yankees stumbled again. Still, they need just one win in their final four games to earn the playoff spot.

Mookie Betts tied it with a seventh-inning homer off Betances – who has allowed six homers this season, all since July 4. Betts connected again in 11th to cap Boston’s season-high sixth straight victory and again deny the Yankees the 10,000th win in their history.

Bailey (0-1) gave up an RBI single to Deven Marrero with one out in the 11th. Chasen Shreve yielded a run-scoring sacrifice to Jackie Bradley Jr. and a two-run homer to Betts.

New York, which dropped to 65-3 when leading after six innings, left 15 on base and was 3 for 14 with runners in scoring position.

Tanaka was rusty in his first start in 12 days, returning from a right hamstring strain to make what should be his final tuneup before a likely start in the wild-card game on Tuesday.

The Japanese star entered with a deceptive 3-0 record against Boston. He allowed 10 earned runs in those starts, but the Yankees romped to big wins in each. He had trouble Wednesday, too, allowing four runs and five hits in five innings on 95 pitches.

He quickly fell behind, giving up a three-run homer to Travis Shaw in the first.

David Ortiz’s RBI single in the third gave him 105 RBIs.