The losing streak is finally over.

The Yankees ended their four-game skid on Thursday with a 2-1 victory over Oakland before 44,346 at the Stadium. Masahiro Tanaka did most of the heavy lifting in accomplishing that feat, but with the Bomber bats still quiet, it took more than that. They needed a sliding catch and a lucky ricochet to eke it out.

Those two fortunate strokes helped the struggling Yankee bullpen negotiate tense circumstances in the final two innings after Tanaka — who can only been seen as this team’s ace now — turned in six gritty innings that have to rank with his best performances in what has been a superb debut season. The relief corps had led the Bombers down the path to defeat for four straight days, and the three keys to its endgame — Dellin Betances, Adam Warren and David Robertson — this time got them to the finish line.

“We were having a little slump, too. We had the lead a couple times and couldn’t hold it. It happens in baseball,” said Robertson, who notched his 13th save with a strikeout of Derek Norris to end it. “We were definitely able to hold it down today. The A’s gave us everything they had. They were scratching tooth and nail — it felt they were fouling every pitch back — and I feel very fortunate to take a win today.”

Tanaka (9-1) bent but never broke while pushing through 104 pitches — including 63 to strand five runners in his last three frames — and the only blemish was John Jaso’s homer in the first. The Yankees knotted the score in the second when Brian McCann’s single was misplayed for an extra base by A’s left fielder Brandon Moss and Alfonso Soriano snapped an 0-for-16 funk with a run-scoring single to right. Brett Gardner led off the third with a homer to the second deck in left for the lead off Oakland starter Drew Pomeranz (5-3).