Nationals catcher Wilson Ramos raises his hand in triumph after launching the three-run shot that buried the visiting Mariners on Tuesday night. (Toni L. Sandys/The Washington Post)

In the Washington Nationals’ clubhouse, they heard the cheers before they knew what happened. The pitchers who had made the most improbable comeback in team history possible watched Wilson Ramos clobber a walk-off home run with ice on their shoulders and a seven-second delay on television. Before they sprinted out to the field to join their delirious teammates, they celebrated together.

“We’re jumping up like we’re 5 years old and won a T-ball game are about to get a snow cone after,” Collin Balester said. “It’s fun. It shows you what this game is about.”

Before Tuesday night’s shocking, 6-5 victory over the Seattle Mariners at Nationals Park, the Nationals had never overcome more than a two-run deficit in the ninth inning. They entered the ninth Tuesday trailing by four. Then they knocked out Seattle’s closer. Then Ramos’s three-run missile to the left-center bleachers, a thunderbolt out of the pitch-black sky, his first career walk-off hit, completed a sudden, stunning reversal.

The Nationals had spent the entire game down a fistful of runs — 5-0 in the sixth. They had been down to their last out for four batters. By the time Ramos swung, then took two slow steps out of the batter’s box, most of the 21,502 at Nationals Park had lost hope and left. Ramos thrust his right index finger into the air.

He said to himself: “The game is over.”

Washington had seemed poised to lose to its second straight following an eight-game winning streak. Instead, it conjured a win that sent them one victory from their first .500 record this late in the season since 2005, the kind of improbable win that could spark another streak.

“We never put our heads down,” Ramos said. “We thought we could win the game.”

The Nationals mounted the rally in the ninth, once Mariners starter Doug Fister exited after 99 pitches with a 5-1 lead and a win halfway in his back pocket. The Nationals managed three runs and a walk against him, and he had thrown three balls to only two batters. He dominated. But then he left.

“You kind of a take deep breath,” Jayson Werth said. “It’s like, ‘He’s gone. Let’s get this guy.’ When the inning started, we felt pretty good about it.”

Flame-throwing closer Brandon League replaced Fister, and somehow his 98-mph fastballs looked more hittable than Fister’s high-80s sinkers. Werth led off the ninth with a grounder that scooted through first baseman Justin Smoak’s legs and turned into a two-base error. Roger Bernadina followed with a seven-pitch walk.

“That showed you that we were zoning him up,” Michael Morse said.

Ryan Zimmerman grounded into his third double play of the night, a 6-4-3 that snuffed out most of the hope that might have been burgeoning for the few fans left in the park. But Jerry Hairston — in the game as a replacement for Laynce Nix, who left in the seventh with a sore Achilles’ tendon — singled up the middle, scoring Werth and bringing the tying run to the on-deck circle. That was a step.

Morse drilled a line drive off League’s right leg, and it dribbled far enough away for him to reach first. League limped into the dugout, forced from the game by a bruised right calf. Danny Espinosa came to the plate, incredibly, with a chance to tie the score.

Against replacement David Pauley, a slight right-hander, Espinosa ripped a single through the right side of the infield, making it 5-3. Up came Ramos, 15 for his last 77. He fouled off the first pitch he saw and took the second for a ball, both fastballs.

Ramos stepped out of the box and thought back to the conversation he’d just had with hitting coach Rick Eckstein in the dugout. As Pauley warmed up, Eckstein told Ramos that against right-handed batters, Pauley’s second-best pitch was a change-up. When Ramos stepped back into the box, Pauley flung an 84-mph change-up that stayed up, over the middle of the plate.

“I was waiting for that pitch,” Ramos said.

He took a gargantuan hack. The ball roared into the night. “You hear that noise and see that trajectory, you know right away,” Werth said later.

Ramos’s home run ball landed about two rows shy of the Red Porch bar in left-center field. He circled the bases slowly and leaped into a pile of teammates. At home plate, they let him have it. And as Ramos gave a television interview later, Morse dumped a bucket of Gatorade on him.

“I wasn’t ready for that,” Ramos said.

Back in the clubhouse, Ryan Mattheus and Balester had watched the TV. They had done their part, pitching two scoreless relief innings each. The Mariners tagged Livan Hernandez for five runs, but the bullpen, which also got a scoreless inning from Todd Coffey, never let the Mariners run away.

“They kept us in reach,” Espinosa said. “It keeps the team rolling – ‘Hey, we still got a shot.’ ”

In the seconds after Ramos’s home run, with Hernandez watching with them, they heard the commotion and wondered.

“We didn’t know what happened yet,” Mattheus said. “We knew it was something good.”

They all ran down the tunnel to pummel Ramos. Hernandez no longer cared about the 10 hits he had given up or the cutter he couldn’t throw quite right. The Nationals were in third place and a game away from .500. They had done something close to impossible.

“Baseball is crazy,” Hernandez said. “You know, baseball is 27 outs. Not too many believe that. But baseball is 27 outs.”