Ryan Zimmermann playfully jukes his teammates as they give chase following another walk-off win for the Nationals. Zimmerman scored on a two-out wild pitch. (Toni L. Sandys/The Washington Post)

What happened at Nationals Park on Tuesday night between the Washington Nationals and the New York Mets is almost too messy to understand. The Nationals sent a young starter to the mound, Ross Detwiler, and he pitched his best game of the season. They sent one of their best relievers to the mound, Tyler Clippard, and he blew a two-run lead and the save. They tied the score with a hitter who struggles from the left side of the plate, Danny Espinosa, and they still gave up the lead.

In the 10th inning, they tried again to win the game — or not lose it — and this time Bryce Harper was at the heart of the rally. He smacked a tying triple, then, after Ryan Zimmerman and Ian Desmond were intentionally walked, Mets reliever Pedro Beato unfurled a wild pitch to Tyler Moore, to give the Nationals a wild 5-4 walk-off win.

“That’s why you come to the ballpark,” Moore said. “The first eight innings were kind of boring and the last three were unbelievable.”

Beato was inserted into the game to face Moore with two outs after Harper was forced out at home on a fielder’s choice. And just like the other Mets relievers before him, Beato pumped only offspeed pitches at Moore. But on his fourth one, he threw a curveball that bounced hard into the dirt to the right of the plate and high over the head of catcher Josh Thole. At third base, Zimmerman started to run home, then stopped because he couldn’t tell from his vantage point exactly where the ball was, then darted to the plate to score the winning run.

Third base coach Bo Porter raced home right behind him to celebrate. Zimmerman ran into the crowd of teammates streaming from the dugout steps. One tried dumping water on him but he escaped, almost like Tuesday’s win against the Mets.

Entering the game, the Nationals had the league’s best record against National League opponents. The Nationals also had the best winning percentage (.621) in the major leagues against division opponents. And this swing of games to start the second half of the season — 21 of 25 against the NL East — would be one of their most decisive stretches of the season. They could distance themselves from the rest of the division or see their lead shrink quickly.

Over the weekend, the division lead shrank against the Miami Marlins, with the surging Atlanta Braves on their tails. And even though they almost lost the game twice and needed to tie the score twice, they narrowly escaped a division loss and maintained a 31 / 2-game lead over the Braves.

“That’s what first-place teams do,” Detwiler said. “They find a way to win every game possible. This is a big month for us.”

Detwiler cruised through the Mets’ lineup, allowing only five hits, inducing groundballs and relying on his defense, and turning in his most complete and longest performance of the season. But Clippard, so consistently dominant for the Nationals, faltered with a two-run lead in the ninth.

He allowed a leadoff single to Thole, who was pinch-hitting, in the ninth. David Wright then singled and instantly, within the span of eight pitches, Clippard was in a jam with no outs. Pinch hitter Jordany Valdespin then crushed a change-up that stayed across the middle of the plate into center field. The ball bounced off the top of the green wall and back into the play. Harper played the ball off the bounce and tossed it in. But home plate umpire Angel Hernandez signaled that it was a home run.

Manager Davey Johnson ran on to the field and asked for a review. The umpires disappeared to watch a replay and returned to reaffirm the ball. In 15 tries as the Nationals’ closer, Clippard had blown his first save. After completing the inning, he walked off the mound, his shoulders shrunk and his head down.

Earlier in the night, Detwiler walked off the mound with his head held high. He tossed seven scoreless innings, allowing only five hits. He needed only 86 pitches to cruise through his start, relying on a strong defense and efficient performance to notch his longest outing of the season.

Detwiler hadn’t pitched in 12 days, his last outing on July 5 against the San Francisco Giants. He, however, showed no ill effects. He worked out of the jams and around the base runners. He attacked hitters with strikes, on the advice of reliever Michael Gonzalez, who pulled him aside before the game. Only two other times in his career has Detwiler thrown at least seven innings.

He allowed a leadoff single to start the second inning, but tossed an inviting sinker to left fielder Jason Bay, who rolled over it to induce a double play. Detwiler then allowed two more singles to the next two batters, but notched a ground ball on a sinker to catcher Mike Nickeas. After allowing a single in the third inning, Detwiler pumped a low fastball to second baseman Ronny Cedeno, who hit into another double play. In all, Detwiler induced eight groundouts.

Moore gave the Nationals a lead when he smacked a solo home run off Niese to right field. Lombardozzi added an insurance run and gave the Nationals a 2-0 lead in the eighth inning when he doubled home pinch hitter Mark DeRosa, a 37-year-old utility player who reached on a walk and stole second to get into scoring position.

But in the ninth, after Clippard blew the save, the Nationals rallied. Michael Morse led off the ninth inning against right-handed reliever Bobby Parnell with a single and Johnson sent injured Desmond in for him to pinch run. Facing a shift, LaRoche smacked a single to left field that moved Desmond, already running on the pitch, to third base. Then came Espinosa, who has struggled hitting from the left side this season. Parnell tossed five straight curveballs with two outs but on the sixth pitch, the first fastball, Espinosa drove it up the middle for a game-tying single.

“I got a couple down in the zone that I chased but it was more just trying to get the ball up on him,” Espinosa said. “It’s a fine line with him because he throws so hard and at times he does pitch up in the zone so just really trying to get a pitch to hit and stayed with my plan.”

But after Michael Gonzalez allowed the Mets to take a 4-3 lead in the 10th inning, the Nationals had to rally again.

Inserted in the 10th and trailing by a run, Jhonatan Solano led off with a single. Harper smacked a triple off of left-handed reliever Tim Byrdak to right field, plating Solano and tying the score at 4. The ball — a bullet as Johnson put it — ricocheted off the right-center field wall. Harper rounded second and dove headfirst into third, the ball bouncing away from Wright and against the dugout railing.

“I was going up there just trying to get something through the infield or something to get him over so [Zimmerman] could drive him in or something,” Harper said. “So I got a pitch I could handle and I was thinking three out of the box and I wasn’t going to stop.”

Mets Manager Terry Collins then called for intentional walks of Zimmerman and Desmond, in pain and unlikely to swing, hoping to have LaRoche face left-handed Byrdak. Harper was forced out at home on a groundball by LaRoche. Then came Moore to the plate, to face Beato, and witness the win.