Chase Headley started the winning rally when he singled to left with two outs off Craig Stammen (0-2). Alonso walked before Maybin singled in front of right-fielder Jayson Werth. Headley easily beat the throw home.
''I managed to get just enough bat on it,'' Maybin said. ''It feels real great. We're grinding, man. It was bigger to get a win tonight. We've been scuffling but we've been battling every night. For me it was huge because we have a chance to win the series tomorrow.''
Joaquin Benoit (2-0) pitched a perfect 11th for the win.
Alonso tied the game at 3 in the ninth when he homered into the Jack Daniel's party deck atop the right-field wall on a 1-1 pitch from Rafael Soriano. It was Alonso's fifth homer and Soriano's second blown save in 14 opportunities.
Alonso's shot denied Washington rookie Blake Treinen his first big league win. Treinen was on track for the win after Ian Desmond hit a 432-foot, two-run home run with two outs in the seventh inning to give the Nationals a 3-2 lead.
Cashner left with a 2-0 lead after six innings in his return from the disabled list. The tall Texan allowed only two hits, struck out five and walked one on 70 pitches. Out since mid-May with a sore right elbow, Cashner retired his final 16 batters and lowered his ERA to 2.13.
''It's good having him back out there,'' Maybin said. ''He's a bulldog. We're confident whenever that guy's out there.''
Cashner got in trouble in the first inning when the Nationals had runners on second and third with one out. But catcher Rene Rivera threw out Kevin Frandsen when he strayed too far off third and Ryan Zimmerman forced Adam LaRoche at second to end the inning.
''It was fun to get back,'' Cashner said. ''First inning there was a little trouble, but it was a big throw by Rene getting that out there. I think my fastball had the most movement I've had in a long time.''
Nick Vincent replaced Cashner and surrendered the lead in a span of five batters. LaRoche doubled with one out and scored on Ryan Zimmerman's double to right. With two outs, Desmond homered well over the 396 sign in center field.
The Padres had the potential winning run on second after Rivera doubled off the left-field wall with one out in the 10th. Chris Denorfia struck out and Everth Cabrera flied out to left.
Rivera was stranded at third in the eighth after he doubled to left and was sacrificed by pinch-hitter Denorfia. Cabrera flied out to center and Carlos Quentin, pinch-hitting for left-hander Will Venable against righty Tyler Clippard, struck out.
Treinen was making his third career start. He allowed two runs and five hits in six innings, struck out one and walked one. After his last start on May 22 his spot was skipped due to two days off.
San Diego took a 2-0 lead against the rookie in the fourth on RBI doubles by Headley and Maybin.
''I felt good physically,'' Treinen said. ''I felt like I was getting myself in trouble by getting behind in counts. But I made pitches when I needed to and then in that one inning I threw some pitches out over the plate.''
NOTES: The Padres drafted Johnny Manziel, the Cleveland Browns quarterback and 2012 Heisman Trophy winner while at Texas A&M, in the 28th round of the MLB draft, the 837th player taken. ... The Nationals drafted Ryan Ripken, the son of Hall of Famer Cal Ripken Jr., in the 15th round. ... Nationals 3B Anthony Rendon sat out with a sore right hand. He was struck trying to field Carlos Quentin's smash in the fourth inning and committed a throwing error. He committed a fielding error the next inning. Manager Matt Williams said Rendon's hand was swollen and ''pretty sore.'' ... To make room for Cashner, LHP Jason Lane was designated for assignment. ... The series concludes Sunday when RHP Jordan Zimmermann (4-2, 3.59) is scheduled to start against lefty Eric Stults (2-6, 5.03).