SAN DIEGO -- Maybe the San Diego Padres found the spark they need to finally secure the NL West title.
"It just doesn't get any better than this," Padres manager Bruce Bochy said.
Greene hit a grand slam to cap a five-run, two-out rally in the ninth inning, and Hernandez had a three-run homer in the 12th inning to give San Diego its second win in seven games.
For a team that leads the NL West with a sub-.500 record and has struggled to distance itself from the rest of the mediocre division, the win was important.
"It was unbelievable, especially coming this time of the year," Hernandez said.
With the victory, San Diego maintained its 5½ game NL West lead over San Francisco, a 2-1 winner over the Los Angeles Dodgers, and reduced its magic number to 10.
The Padres are 73-74, the latest in a season that a team has led a division with a losing record. San Diego has 15 games remaining.
The loss was especially tough for Washington, which fell 3½ games behind Houston in the NL wild-card race with 13 games left.
"We took a huge step backward when it looked like we would gain ground," Nationals manager Frank Robinson said.
Greene led off the 12th with a single, tying his career high with his fourth hit. Pitcher Woody Williams pinch hit and struck out when his bunt attempt with two strikes went foul. Dave Roberts followed with a bloop single to right, with Greene stopping at second. Hernandez then homered on the first pitch from Jon Rauch (1-4) for San Diego's first walkoff homer of the season.
"When I hit it, I had no doubt it was gone," said Hernandez, who hit his 10th home run and was in the center of a prolonged celebration at home plate.
"I messed up," Rauch said. "I hung a curveball, plain and simple."
Scott Linebrink (7-1) pitched two perfect innings for the victory.
The Padres have struggled offensively, scoring three runs or less eight times in 14 September games coming into the game. But San Diego was able to overcome a 5-0 deficit in the ninth to tie the game on Greene's grand slam off Washington closer Chad Cordero.
Greene hit a 1-0 fastball into the left-field stands and was mobbed by his teammates as he approached the San Diego dugout. It was Greene's 12th home run.
"I'm not a big believer in one or two games making a difference in a season," Greene said. "But it was a moment that I'll look back on as the biggest moment of the season."
Eric Young started the rally with a leadoff walk against Jason Bergmann, the first of four Washington pitchers in the ninth. After Bergmann struck out Ramon Hernandez, he was replaced by Joey Eischen, who got one out before allowing a single to Xavier Nady. Travis Hughes came in and allowed Joe Randa's RBI single.
Cordero, the major league leader with 46 saves, replaced Hughes and walked Mark Loretta before giving up Greene's grand slam. Pinch-hitter Ryan Klesko ended the inning with a deep fly out to center.
Cordero has blown seven save chances.
"I just went out and blew it again," Cordero said. "I tried to get the ball away from the plate. It came back over and he made me pay for it."
The Padres' comeback ruined six shutout innings thrown by Hector Carrasco, who was one out away from his first career win as a starter. Carrasco allowed just three hits and Washington took a four-hit shutout into the ninth inning.
Carrasco, starting for only the third time in 559 games, allowed one runner to reach second base. He struck out three and walked one.
It was Carrasco's second straight start after filling in for John Patterson, who fell ill before Tuesday's game against the New York Mets. Carrasco started on late notice Tuesday and did not receive a decision after giving up two runs on three hits in four innings.
Adam Eaton started for the fourth time since coming off the disabled list with a strained right middle finger. Eaton allowed four runs on eight hits in 5 1/3 innings. The right-hander struck out five and walked two.
- Johnson hit his 14th homer leading off the second inning and Wilson hit his 24th homer to lead off the sixth and give the Nationals a 4-0 lead.
- Before this season, Carrasco's only other start came with Boston when he pitched two innings on Oct. 1, 2000.
- Greene hit his first career grand slam and it was San Diego's first in the two-year history at Petco Park.