PHILADELPHIA -- Still clinging to postseason hopes, the Washington Nationals will take every win they can get.

Wilson Ramos hit a three-run homer and Corey Brown also went deep to back Gio Gonzalez, helping the Nationals beat the Philadelphia Phillies 9-6 Tuesday night.

The Nationals remained 7 1/2 games behind Cincinnati for the second wild-card spot after overcoming a sloppy all-around effort that included three errors, four unearned runs and four wild pitches.

"That was an ugly game, one of the ugliest I've seen," manager Davey Johnson said. "That's not the way to win a pennant, I'll tell you that."

Gonzalez (9-6) gave up five runs -- one earned -- and five hits, striking out six in 5 2/3 innings. The lefty has two straight wins after going seven starts without one.

Ramos connected in the second and the Nationals never trailed. Brown hit a solo shot into the second deck off Luis Garcia in his first big-league at-bat of the season in the seventh to extend the lead to 8-5.

"The first time back there were a lot of emotions going on," Brown said. "I just tried to tell myself to get a good pitch to hit."

Phillies rookie Ethan Martin (2-4) allowed five runs and four hits in 4 2/3 innings. The righty hasn't reached five innings in his last three starts.

"It's frustrating," Martin said. "I'm trying to go as deep as I can and when I can't do that, it's frustrating."

Cody Asche was 3 for 4 with a homer and three RBIs for Philadelphia.

Rafael Soriano tossed a scoreless ninth for his 37th save in 43 chances.

A crowd of 28,826 was the smallest at Citizens Bank Park since April 3, 2008, when 25,831 turned out for a game, also against the Nationals, according to STATS LLC. That was the last time the Phillies drew under 30,000.

After leading the majors in attendance in 2011-12, the Phillies are fourth in the NL this season. But they're averaging 6,000 fewer people than last year.

Gonzalez faced a lineup missing Jimmy RollinsChase Utley and Domonic Brown. Rollins and Utley had the day off and Brown remains sidelined with soreness in his right Achilles.

"I was a little uncomfortable the whole game," Gonzalez said. "They were being patient and I wasn't pounding the strike zone. A win doesn't have to be pretty, but just a win."

Control issues cost Martin. He hit Jayson Werth on the left forearm with a 93 mph fastball leading off the second. After Adam LaRoche's one-out walk, Ramos drove one out to right-center for a 3-0 lead.

Martin walked three in the fifth, including LaRoche with two outs and the bases loaded to force in a run. Justin De Fratus came in and walked Ramos to force in Washington's fifth run.

Werth and Ian Desmond had RBI singles in the sixth for the Nationals to make it 7-2.

Asche's two-run single in the fourth got the Phillies within one. Kevin Frandsen led off with a single and Carlos Ruiz reached on third baseman Ryan Zimmerman's fielding error. They advanced on a wild pitch and scored on Asche's hit up the middle.

Shoddy defense hurt Gonzalez again in the sixth. With two outs, John Mayberry Jr. reached on shortstop Desmond's throwing error that scored Darin RufMichael Martinez followed with an RBI single and went all the way to third on catcher Ramos' fielding error. Gonzalez exited and pinch-hitter Utley greeted Ryan Mattheus with an RBI single that cut it to 7-5.

"There's a few cracks in the dam and I'm trying to plug them, but I'm running out of fingers," Johnson said.

Game notes

Nats LF Bryce Harper started running in after catching the second out in the eighth inning before realizing his mistake. He smiled and took some verbal abuse from the remaining fans. ... Denard Span extended his hitting streak to a career-high 16 games with a third-inning single. ... Phillies LHP Mauricio Robles made his major league debut, allowing two unearned runs in an inning. ... The Nationals selected SS Zach Walters and recalled Brown, LHP Xavier Cedeno, INF/OF Jeff Kobernus and OF Eury Perez from Triple-A Syracuse. ...Jordan Zimmermann (15-8) opposes Roy Halladay (3-4) when the teams finish the series Wednesday.

More From 97.3 ESPN