WASHINGTON -- Wilson Ramos knew it as soon as the ball left his bat. Teammate Jayson Werth jumped out of the dugout to start celebrating, without even bothering to see where the drive landed.

Ramos capped Washington's five-run ninth inning with a game-ending three-run homer, lifting the Nationals to a dramatic 6-5 victory over the Seattle Mariners on Tuesday night.

"I hit that ball pretty good," Ramos said. "After I hit the ball, I knew that ball was in the stands."

The rookie catcher's shot finished the biggest ninth-inning comeback for the Nationals since the team moved to Washington from Montreal in 2005. It also tied the largest ninth-inning comeback in franchise history.

Jerry Hairston Jr. and Danny Espinosa each had two-out RBI singles before Ramos connected on a 1-1 pitch from David Pauley for his sixth homer. Ramos threw his arms up almost immediately after the ball left his bat and Pauley (4-1) trudged off the mound.

The Nationals ran out of the dugout and waited for Ramos to touch home plate before starting a mass celebration.

"It went about 20 feet off his bat and I hopped over the fence. I knew right away," Werth said. "I didn't even look to see where it went."

The Mariners wasted a fine effort from Doug Fister, who allowed one run and three hits in eight innings. The right-hander is 0-3 in four June starts despite a 3.60 ERA.

Brandon League replaced Fister for the ninth and Werth reached on a two-base error by first baseman Justin Smoak to begin the inning. Roger Bernadina walked before Ryan Zimmerman hit into a double play, leaving Werth on third.

Hairston followed with his run-scoring single and Michael Morse reached on a comebacker that hit League in the right leg. League took some practice pitches before he was replaced by Pauley, who surrendered Espinosa's hit to set the stage for Ramos.

"I was pretty excited after I hit that homer," Ramos said. "That was my first walk-off home run in my career. So when I saw my teammates waiting for me at home plate, I was very, very excited."

Adam Kennedy had three hits and two RBIs for Seattle, which finished with 13 hits. Prized prospect Dustin Ackley also drove in two runs.

Washington starter Livan Hernandez was chased in the fifth inning -- his shortest outing of the season -- and charged with five runs, four earned, and 10 hits.

Fister cruised through much of the game. He retired 10 straight after Werth's leadoff single in the first. An infield hit by Zimmerman ended the run, but Fister set down the next five batters before Washington got its first real offensive chance.

Fister hit Ian Desmond and walked Werth with one out in the sixth, and Bernadina singled in Desmond. Fister quickly ended the jam with a double-play ball from Zimmerman, and the Nationals did not have another baserunner until the ninth inning.

"Every once in a while, you're going to get kicked in the teeth like this," Seattle manager Eric Wedge said. "When you do, you've got to pick yourself up, learn from it, shelve it and come back out with a fresh state of mind."

Three relievers shut down the Mariners after Hernandez left. Ryan Mattheus and Collin Balester each pitched two innings, and Todd Coffey (3-0) worked the ninth for Washington, which has won nine of 10.

The pitchers who had left the game watched from the clubhouse, where they heard the roar of the crowd before seeing the home run on the televised feed.

"We're jumping up like we're 5 years old and won a tee-ball game and we're getting a sno-cone after," Balester said. "It's fun. It shows you what this game is about."

Game notes

Washington left fielder Laynce Nix left after the seventh inning with a sore right Achilles and is day to day. Washington manager Jim Riggleman said he will not play Wednesday. ... The Nationals celebrated the 20th anniversary of catcher Ivan Rodriguez's first major league appearance with a montage on the videoboard before the game. Rodriguez made his debut on June 20, 1991, with the Texas Rangers. ... Zimmerman extended his hitting streak to 10 games, dating to April 7. Zimmerman has hit safely in all seven contests since missing 58 games with an injured abdominal muscle. ... The Mariners made their first visit to D.C. since 2005 and their first ever visit to Nationals Park.