Ian Demond scores on a bases loaded wild pitch by Michael Wacha in the seventh inning to give Washington a lead it would not relinquish at Nationals Park. (John McDonnell/The Washington Post)

Over the past 18 months, the Washington Nationals have been devastated, harassed and embarrassed by the St. Louis Cardinals. On Friday, for one night at Nationals Park, the script reversed. The Nationals played crisp baseball and stared down their tormenters until, at the most crucial moment, the Cardinals cracked. For one night, the bully stepped on a rake.

Before their 3-1 victory over the Cardinals — and even during both the game’s go-ahead rally and the night’s defining escape — the Nationals may have wondered what it would take to beat St. Louis. The Cardinals treated every meeting like they were filming an instructional video: relentless at the plate, smart on the bases, flawless in the field, oppressive on the mound.

For once, the Cardinals broke character. After Gio Gonzalez and Michael Wacha locked horns for seven innings, the Nationals broke a 1-1 tie when Wacha unfurled a wild pitch with the bases loaded and Ian Desmond made a bold dash home. Yadier Molina, an obelisk behind the plate, flipped the ball past Wacha as he covered home. Just as Wacha threatened to squirm out of a bases-loaded, no-out jam, the Nationals finally got to watch the other team self-combust.

“You never see a ball get away from Yadi,” Nationals Manager Matt Williams said. “Ever.”

Once the Nationals wrested the lead, they held on for dear life. Tyler Clippard put the first two hitters he faced on base and made 26 pitches to record one out. Drew Storen, victimized so infamously in the game that started the Cardinals’ streak against the Nationals, relieved him with two runners in scoring position and one out. Five pitches later, with Matt Holliday and Allen Craig in his wake, Storen slapped his glove and walked off the field with the Nationals’ two-run lead preserved.

Rafael Soriano worked the ninth for his fourth save, helped by Desmond’s emphatic, athletic double play turn to end it. One night after they committed a pile of misplays in an 8-0 shipwreck, the Nationals snapped an eight-game losing streak to the Cardinals that began in Game 5 of the 2012 National League Division Series.

“We played great as a team,” Gonzalez said. “It was one of those games, we needed it. We needed to bounce back.”

The Nationals will throw Jordan Zimmermann and Stephen Strasburg at Lance Lynn and Shelby Miller over the weekend with a chance to win the series, largely because Gonzalez, another Game 5 goat, supplied seven sterling innings. After the Cardinals used three straight hits to score their only run in the fourth, Gonzalez retired the final 11 batters he faced, striking out four.

Gonzalez ensured Anthony Rendon’s third-inning, solo homer would be enough to keep the score tied. In the seventh inning, the Nationals grabbed the lead.

Adam LaRoche sparked the go-ahead rally with a bloop single to left field. Desmond followed with a single to right. Danny Espinosa tried to push them both into scoring position with a textbook bunt toward third base. Wacha scampered off the mound, but rather than taking the sure out, he spun and tried to snare LaRoche at third. The ball popped out of Matt Carpenter’s glove, an error on Carpenter that loaded the bases with no outs.

For a moment, the Cardinals played like they usually do, as if the natural order of things dictates everything works out for them in the end. Wacha struck out Nate McLouth, who dropped to 2 for 26. Jose Lobaton hit a dribbler that Wacha handled and flicked home for a force out.

“That’s why they’ve won so many ballgames,” Williams said. “They’ve got the ability to shut you down, too. You have to continue to think about any way to score.”

With Gonzalez’s spot up, Williams sent call-up Zach Walters to pinch hit. Desmond noticed Carpenter playing back with two outs, which enabled him to dance farther off third base on his secondary lead.

Desmond anticipated Molina would call for Wacha to throw Walters change-ups — earlier in the week in Miami, Walters had blasted a pair of fastballs over the fence. “Yadi,” Desmond said, “is smart.” Desmond knew if Wacha threw a pitch that started at the shins, it would likely be a change-up headed for the dirt.

Walters flailed at Wacha’s first-pitch change-up. Walters stayed patient for two balls. Wacha held on to his 2-1 change-up too long.

With his large secondary lead, alert for a ball in the dirt, Desmond thought: “We’ve got a chance here.”

The ball scooted to Molina’s right, and Desmond decided immediately. He bolted. Desmond slid home, into Wacha’s legs, as Molina’s misfire skipped into the dugout. Espinosa scored, too, and the Nationals had taken a two-run lead.

Clippard immediately endangered it. Jon Jay greeted him with a double, and Carpenter followed with a walk. Jhonny Peralta ended a 12-pitch at-bat by one-hopping a laser back at Clippard, which he fielded for an out.

With Clippard on fumes and Holliday lumbering to the plate, Williams called on Storen. Storen fired his first pitch 95 mph and down the middle of the plate. The two-seam fastball, as planned, cut inside enough for Holliday to hit off the trademark and pop up. Craig hit a one-hopper to shortstop, and Storen had delivered the two biggest outs of the game.

“That’s kind of the fun part about it,” Storen said. “You’re always on your toes no matter what. You get the adrenaline going a little bit, change it up. Anytime you can go out there and save another guy’s run, that’s pretty fun.”

In the ninth inning, the crowd roared as Soriano yielded a four-pitch walk to Mark Ellis. With a 1-2 sinker, Soriano induced a grounder up the middle from Shane Robinson.

Some six hours earlier, every Nationals pitcher had gathered on the mound for early fielding practice. Following the Nationals’ defensive meltdown Thursday night, Williams vowed the Nationals would forge ahead with preparation and work. “It’s scheduled extra work for the pitchers tomorrow,” he said then. “It’s part of the schedule.”

And so, Friday afternoon, Soriano had practiced the exact play Robinson presented him: a hard chopper back at him. Soriano snared the ball, turned and fired a strike to Desmond. As Ellis barreled into him — “aggressive takeout slide,” Williams said — Desmond leapt and rifled the ball to first for a game-ending double play.

Among all the story lines from the night — Storen’s mini-redemption, the Cardinals’ rare implosion, a needed win over a strong opponent — that was the one that pleased the Nationals most.

Tomorrow came, and they played as they are capable.

“It’s one win,” Desmond said. “We still have a lot of baseball to play, and obviously we’ve got to play them again. They’ve got a really good team. And so do we.”