The loud sound that filled a half-empty Yankee Stadium immediately let those who remained know the home team was going to present Mariano Rivera with a one-run lead to work the final inning.

There was no need to follow the flight of Travis Hafner’s solo homer, because the sound was loud enough and solid enough to know that with Hafner’s strength and the cozy Yankee Stadium right field the ball was easily going to clear the wall.

“Moments like this are really special, and you remember them for a long time,’’ Hafner said of his game-winning homer off Arizona’s David Hernandez that carried the Yankees to a 4-3 come-from-behind victory in front of an announced crowd of 34,369.

Hafner, who didn’t start the game against lefty Wade Miley, went to the plate with two outs and the score tied, 3-3. One pitch was all he needed to put the Yankees three outs from a victory that Rivera saved with a perfect ninth inning.

“I saw him throw Robbie [Cano] three or four breaking balls,’’ Hafner said of Hernandez, who watched Cano line out opening the frame. “I was only looking for a good pitch to hit, but he throws 95 to 96 mph so have to be ready for that.’’

Hernandez opted for a fastball and paid the price.

“I was excited,’’ CC Sabathia said of watching Hafner walk to the plate as the hitter for Ben Francisco. “In this ballpark with his power …’’

Rivera recorded his fourth save of the season and upped the all-time saves record to 612.

The win, which hiked Sabathia’s record to 3-1, was the 8-5 Yankees’ third straight and seventh in eight games.

For six innings it looked like the three runs Sabathia gave up were going to get him beat because Miley allowed two hits and faced only one Yankee with a runner in scoring position.

“You always want to keep it as close as possible,’’ said Sabathia, who gave up a two-run homer to Paul Goldschmidt in the first and a solo run in the fifth. “Give these guys a chance to swing the bat.’’