Hernandez started the winning rally with a two-out walk against Tyler Clippard (6-3). He came around to score on Rollins' double.
"I was really hoping [Hernandez got on base] so I could get up there and have a chance to do something," Rollins said. "We put some at-bats together and it worked out."
After Chase Utley was walked intentionally, Ruiz drove in Rollins with a single to left.
B.J. Rosenberg (1-0) recorded the final out of the eighth for the win and Jonathan Papelbon finished for his 24th save in 30 chances.
"That was really a tough one; it really hurt," Nationals manager Davey Johnson said. "It was like a stab in the heart."
Ryan Zimmerman homered for Washington, which had won nine of 12. The Nationals fell 7 games back of Cincinnati for the second NL wild card.
"We had opportunities. but we couldn't get it done," Johnson said.
The Nationals took a 2-1 lead in the eighth on Scott Hairston's bases-loaded sacrifice fly that scored Rendon. Hernandez, a converted infielder who was playing his first career game in center, fielded the ball in shallow center field but his throw went weakly up the third-base line.
"It was quite a pitchers' battle," Phillies interim manager Ryne Sandberg said.
Hamels struck out eight in seven sharp innings, limiting the Nationals to one run and two hits. He threw 87 pitches, 69 for strikes.
Hamels has a 1.90 ERA in his last seven starts but has just two wins during that span. The left-hander's record stands at 6-13, thanks partly to the fourth-lowest run support (3.44) among all major league starters entering Monday's action.
The performance was somewhat surprising considering Hamels struggled to find his rhythm in his pregame bullpen session.
"Sometimes later in the year it's hard to get loose," he said.
But facing Strasburg helped, he said.
"Anytime you get to compete against the best, you try to up your game," Hamels said. "You try to throw zeroes just like he's doing. I definitely would take pitching against him more often than not because you feel like you really do have to strive for perfection."
Strasburg fanned 10 while giving up an unearned run and two hits in six innings. He threw 100 pitches, 64 for strikes.
The right-hander said he struggled maintaining his grip on the ball on a humid evening that began with a gametime temperature of 81 degrees.
"I was sweating a lot out there," he said. "It affected me not being able to pitch more innings. Strange circumstances but I have to be able to deal with it. It was tough gripping the ball like I usually do."
Zimmerman connected on an 0-2 pitch in the first for his 16th homer. Washington got just two baserunners off Hamels from that point, with Ramos reaching on an error in the fifth and Bryce Harper singling in the sixth.
Strasburg was equally stingy. His only blemish was Ruiz's broken-bat RBI single in the fourth that scored Rollins, who had walked. It was an unearned run because Rollins reached second when Ramos' throw trying to pick him off at first hit Utley's bat and went to the backstop.
Strasburg's record, like Hamels', isn't indicative of how well he has pitched. Strasburg has a 2.41 ERA in his last six starts but has just one win during the stretch.
The teams combined to use seven relievers after the starters left.
Johnson said Harper has a sore hip. "He keeps saying, `I'm fine, I'm fine.' He's a tough kid," Johnson said. "That's the way he is." Harper missed 31 games with a left knee injury earlier this season. ... Hairston entered with a .412 average (14 for 34) and five homers against Hamels, but went 0 for 3 with three strikeouts against the lanky lefty. ... The three-game series continues Tuesday night when Washington LHP Gio Gonzalez (8-6, 3.56 ERA) opposes RHP Ethan Martin (2-3, 6.39 ERA). ... INF Freddy Galvis and RHP Tyler Cloyd were among the six players the Phillies called up from Triple-A Lehigh Valley. Philadelphia also recalled relievers Luis Garcia, Mauricio Robles and Joe Savery, and purchased the contract of C Cameron Rupp from Lehigh Valley.