Shortstop Ian Desmond (2 for 4, RBI) rifles a throw across the diamond on Tuesday night in Philadelphia. (Matt Slocum/Associated Press)

If the Washington Nationals are indeed serious about keeping their slim playoff hopes alive, they need to seize upon the blunders of their opponents. The notion may seem like a simple one, but the Nationals had failed to do so in losing three of their previous four games to struggling division foes. On Tuesday night, they finally seemed to grasp the concept but not without making plenty of their own mistakes in a sloppy 9-6 win over the Philadelphia Phillies.

“One of the uglier ones I’ve seen,” Nationals Manager Davey Johnson said. “. . . That’s not the way you win pennants,”

The Nationals remained 71/ 2 games behind the Cincinnati Reds in the hunt for the second National League wild-card bid, but their uneven play inspires little confidence of a last-gasp playoff run with 24 games remaining. Starter Gio Gonzalez couldn’t get out of the sixth inning. Bryce Harper forgot the number of outs in the eighth, and three Nationals errors contributed to four unearned runs. The Nationals used five pitchers and threw 167 pitches, 100 for strikes. The game featured 13 walks, five wild pitches, one balk and four errors in total.

“We were a young team last year, and we were in a pennant race, and we handled it all right,” Johnson said. “But we still aren’t out of it. We’re just not handling things as individuals. We have a few cracks in the dam. I need to plug ’em. I’m running out of fingers.”

The Nationals built a five-run lead by the top of the sixth inning by capitalizing on the Phillies’ mistakes. With Jayson Werth and Adam LaRoche on base, Wilson Ramos hammered a three-run homer in the second inning. In the fifth, the Phillies handed the Nationals a pair of runs on consecutive bases-loaded walks. The Nationals even scored a late run on a strikeout. Wackiness abounded.

The Post Sports Live crew discusses the Nationals' slim chances of making the playoffs and whether it matters that Bryce Harper hid his hip injury from manager Davey Johnson. (Post Sports Live/The Washington Post)

The Nationals took a 7-2 lead in the sixth with run-scoring hits from Werth and Ian Desmond. At the center of both rallies was Denard Span, who extended his hitting streak to 16 games and raised his average to .278 with three hits on the night.

Gonzalez wouldn’t make it out of the bottom of the inning.

Staked to a 3-0 lead, Gonzalez let the Phillies back in the game in the fourth when Cody Asche followed an error and wild pitch with a two-run single to cut the margin to 3-2. While Gonzalez didn’t make it any easier on himself with three walks and two wild pitches over 52 / 3 innings, only one of the five runs he allowed was charged to him because of miscues and three errors behind him.

“A win doesn’t have to be pretty. It just has to be a win,” Gonzalez said.

With a five-run lead in the sixth, the Nationals played little like a team gunning for the playoffs. Gonzalez walked Darin Ruf with one out and then allowed him to advance on a wild pitch. After Asche lined out, Gonzalez induced a groundball from John Mayberry. Desmond fielded the ball, but his quick throw was low, and LaRoche couldn’t scoop it at first base. Ruf scored and Desmond was charged with a throwing error. Pitching coach Steve McCatty paid Gonzalez a visit on the mound. Gonzalez was searching for a consistent arm slot.

“Phillies had a lot of walks. We had a little bit of walks,” Gonzalez said. “So it was all around just one of these weird games. You just can’t explain it.”

The mistakes continued. Gonzalez surrendered a single to left to Michael Martinez, and the Nationals threw the ball around the field. Harper fired a strike home to Ramos, but the ball appeared to pop out as he tried to tag Mayberry on the rapid-fire play. The ball skipped to the backstop to the right of home plate, but Gonzalez wasn’t there. Martinez took second on the throw and then third as Ramos chased down the loose ball. The catcher was charged with the error.

Johnson had seen enough and hooked Gonzalez. Ryan Mattheus’s first pitch was mashed to left by pinch-hitter Chase Utley. Needing only one out, the shaky Nationals allowed three runs and seemed poised to blow the lead. Mattheus escaped the inning but not before firing two wild pitches.

The Nationals and Phillies would continue to trade miscues. September call-up Corey Brown mashed a pinch-hit homer to the second deck in right field in the seventh. In the eighth, Tyler Clippard served up a solo shot to Asche. After catching a flyout in left, Harper ran toward the dugout. It was only the second out. The sparse crowd of 28,826 booed Harper. He stopped and ran back to his spot in left, laughing the entire way.

“He’s a thrill a minute,” Johnson said, smiling, of Harper.

The Nationals scored a run in the ninth when Harper struck out with the bases loaded but B.J. Rosenberg’s pitch went to the backstop. After Nationals closer Rafael Soriano put two men on in the bottom of the inning, he induced a double play to end the game after a tidy 3 hours 38 minutes.

“As ugly as it was, it sure was delightful to win,” Johnson said.