Denard Span is swarmed by teammates after hitting a game-ending sacrifice fly to beat the Cardinals. (Katherine Frey/The Washington Post)

Denard Span peered from the batter’s box past the pitcher’s mound, through the shadows criss-crossing the Nationals Park infield early Sunday evening, and started counting fielders. He had walked to the plate intent on ending what he would later call a “roller coaster” series — it already had included an emphatic drubbing, a pitching duel and a controversial benching. The St. Louis Cardinals provided one final, desperate wrinkle by turning an outfielder into a fifth infielder.

“A groundball is probably not going to do it,” Span recalled thinking. “Try to get the ball in the air somehow.”

Like so many Washington Nationals batters before him, Span carried a plan to the plate, then executed it. Span completed the Nationals’ 3-2 comeback victory with a bases-loaded sacrifice fly to left field that scored Danny Espinosa, forcing a series split against the defending National League champions by clawing back against the mighty back end of the Cardinals’ bullpen.

Faced with a customary deficit Sunday afternoon, the Nationals squandered opportunities but never stopped creating them. The Nationals set up the dogpile on Span with two runs in the seventh off flamethrowing Carlos Martinez, salvaging Stephen Strasburg’s six-inning, two-run, nine-strikeout start and giving meaning to a dominant relief performance of their own.

On Thursday night, the Nationals committed three errors, botched several more plays and earned both an 8-0 loss — their eighth straight to the Cardinals — and a tongue-lashing from Manager Matt Williams. They won two of the next three, putting on pause the narrative that they cannot beat elite teams.

The series split came with a hidden accomplishment. In their past five games, the Nationals faced Jose Fernandez, Adam Wainwright, Michael Wacha, Lance Lynn and Shelby Miller, a succession of wicked arms they may not see again all year. And they managed to beat three.

“You can hang your hat on that,” right fielder Jayson Werth said. “I feel like we battled. We got our [butts] kicked the one night. We’re playing good ball. I feel like one night, you guys are talking about how awful we are. The next night, it’s how good we are. We got a long way to go. We just need to stay the course.”

On Sunday morning, the story line of the previous afternoon still hovered. Williams walked into the clubhouse and sat next to Bryce Harper, the 21-year-old star he had pulled from Saturday’s loss for “the inability to run 90 feet.” The decision had won Williams clubhouse support, and now the first-year manager wanted to build Harper back up.

“It was good,” Williams said. “Just sat with him for a couple minutes at his locker and told him I’m confident in him and proud of him and he was going to have an impact.”

“He just said, ‘Go get ’em,’ ” Harper said. “Those were the three words he said.”

Harper went 1 for 4 and stole his way into scoring position in the eighth inning, even though the Nationals saved the final stage of another comeback for the ninth.

Does it feel like the Nationals have played from behind all season? That’s because they have. The Nationals have scored first in just seven of 19 games. They have played 173 innings this year, and they have led after only 58 of them. And still, they have managed to finish ahead in 11 of 19 games.

Sunday provided an explanation. The Nationals went 2 for 12 with runners in scoring position and stranded 17 base runners, which served as a testament to the persistent quality at-bats they strung together. Against stud right-hander Miller and the Cardinals’ menacing bullpen, the Nationals pounded 11 hits — all singles — and drew seven walks.

Their offense has battered the ball even with starters injured. On Sunday afternoon, Espinosa and Jose Lobaton — the replacements for Ryan Zimmerman and Wilson Ramos — went 6 for 9 with a walk.

“We just stayed the course,” Span said. “I think that’s the biggest difference. As a team, we’re having good at-bats. We’re giving ourselves a chance to get back in ballgames by getting base runners.”

In the seventh, they broke through with a torrent of loud contact off Martinez, who fires 98-mph seeds. The Nationals scalded four straight singles. Adam LaRoche sparked the rally with a liner that nearly decapitated Martinez. Anthony Rendon smoked another single to center. Ian Desmond ripped a two-hopper off second baseman Daniel Descalso’s glove, which scored LaRoche. With the rally in full swing, Espinosa turned around a 98-mph fastball for a game-tying RBI.

Espinosa also sparked the Nationals’ game-winning rally with a single through third baseman Matt Carpenter’s legs. Lobaton rolled a single through the right side, which sent Espinosa to third, 90 feet away from winning the game with one out.

Williams tabbed Nate McLouth, 2 for 27 on the year, as his pinch hitter. Later, he would cite McLouth’s at-bat as an example of the Nationals’ approach — McLouth took reliever Seth Maness’s 3-2 pitch just off the outside corner.

“The numbers, the hits, haven’t been there,” McLouth said. “But I haven’t felt terrible at the plate.”

Cardinals Manager Mike Matheny called in left fielder Allen Craig to form the five-man infield against Span. Span stayed alive when he nicked a 1-2 change-up off his foot, and he took a 1-2 sinker just off the inside corner.

“I remember the one I took,” Span said. “I can’t remember which ones I fouled off, to be honest with you. I was so in the moment. It was just a tough at-bat.”

Span lofted a change-up over all five infielders to left. Once Span and Espinosa saw Jon Jay turn his back to catch the ball, they knew they had won.

Span screamed as teammates charged at him, cognizant of not wanting to get hit in the head a day after returning to the lineup from a concussion but covered in Gatorade and too happy to really care.

“In that moment, it’s the adrenaline and just the excitement,” Span said. “I was in the moment, having fun.”