Brian McCann appeared to give and take, grabbing at his knee and hobbling briefly after rounding first base on a solo home run that brought the Yankees to within four in the eighth inning. But the catcher’s health woes lifted and so did his team’s fortune.

McCann hit a three-run homer to tie the score at 7 in the ninth and Didi Gregorius hit a walk-off home run two batters later, as the Yankees beat the Texas Rangers, 9-7, Wednesday night at the Stadium.

McCann, who went 2-for-3 with three runs scored and four RBIs, had his second multi-home run game of the season. He became the first Yankee to hit a game-tying home run in the ninth inning or later with the team trailing by at least three runs since Shelley Duncan hit a three-run bomb against Baltimore on Aug. 15, 2007.

“It was a huge win,” McCann said. “We felt like the one two days ago got away.”

On motioning to his leg: “I’ve got patella tendinitis,” he added. “I’ve been dealing with it for a little bit. I hit first base and something grabbed. Rounding the bases I didn’t know what to think. It just kind of grabbed on me.”

advertisement | advertise on newsday

McCann said his team hasn’t been playing its best baseball recently — the Yankees lost three straight heading into the day, two of the losses by six-run margins — and added that a win like that could be the start of a surge.

Manager Joe Girardi praised his team’s late effort in the face of a large deficit.

“You know you’ve got a lot of work to do,” Girardi said. “You know if you get a couple guys on, you get some guys coming up who can hit the ball out of the ballpark, and that’s what we did. We got a huge hit (from) Mac. Even the homer before kept us in the game, and then you get a huge one from Mac and a big one from Didi.”

Added McCann: “These wins are great. You don’t hit all game and then all of the sudden everybody puts together great at-bats. I just look at it like we’ve got to show up here every day and continue to put W’s on the board. And we’ve got three months to get this done.”