Pittsburgh’s Neil Walker rounds third base after hitting a solo home run off Stephen Strasburg in the fourth inning. (Justin K. Aller/Getty Images)

The situation had been engineered for Stephen Strasburg. His manager kept him on the mound even after he had yielded the game-tying run, even when it took an intentional walk to find a more advantageous matchup. In the seventh inning Saturday night, with the go-ahead run on second base, Matt Williams ordered his relievers to shelter in place. Strasburg had been brilliant for so much of the night, and he would dictate the outcome.

“He’s our ace,” Williams said. “He deserves a chance to get out of that.”

Needing a win to snap a three-game losing streak and remain above .500, the Washington Nationals handed the ball to Strasburg. Williams kept it there until the pivotal moment of the Nationals’ 3-2 loss to the Pittsburgh Pirates at PNC Park, eschewing his rock-solid bullpen as a rally mounted. Pirates outfielder Josh Harrison rolled Strasburg’s 110th and final pitch into center field for an RBI single, the decisive blow in the Nationals’ fourth consecutive loss.

“It’s a good test,” Strasburg said. “Not one guy in this clubhouse was expecting it to be easy from start to finish. We just got to maybe take a step back and maybe let the game come to us, not try and do too much. Just stay in your lane. Just do your job.”

Strasburg (3-4) outdueled fellow No. 1 overall Gerrit Cole for the first six innings. He yielded just three runs in seven innings, allowing seven hits and striking out seven. And still, after Williams left him on the mound to finish the seventh, the Nationals fell to 24-25, under .500 for the first time all season.

Outfielder Jayson Werth, who went 0 for 3 with a walk, found solace in the Nationals’ competitiveness while playing with a diminished lineup. They have lost five of their past six, but four of those defeats came by one run, the other by two. The Nationals have not lost a game by more than three runs since May 9. Then again, the standings do not care about margin of victory.

“The thing about is, we’re battling,” Werth said. “There’s not too many games that we’re not in, especially when it comes to late in the game. We’re playing good baseball. As time goes on and we start getting healthier, we’ll be all right. We definitely need to keep our head above water right now. But I don’t mind the way we’re playing.”

Strasburg allowed the Pirates’ rally in the seventh, but after another meager output the Nationals’ offense shouldered the brunt of the blame. They have scored seven runs during the four-game skid, and Saturday night they let Cole off the hook even while making him throw 98 pitches in his first five innings.

Strasburg cruised into the seventh inning, having allowed just four hits and one walk. The Pirates sprung to life with Russell Martin’s leadoff single. With one out, Starling Marte golfed a curveball off the right field fence, which placed two runners in scoring position.

“The big pitch that killed me was I tried to bury that curveball to Marte,” Strasburg said. “He put a good swing on it.”

Pirates Manager Clint Hurdle sent Jose Tabata to pinch-hit. Tabata had only hit flyballs in 17 percent of his plate appearances, but against Strasburg he roped a high, 2-1 fastball to center field, deep enough for Martin to dash across the plate with the tying run.

Now, Williams faced a decision. Hurdle sent left-handed hitter Travis Snider to pinch-hit. Jerry Blevins, who has held left-handed batters to a .125 average this year, was warmed up in the bullpen. Hurdle had lefty-mashing Gaby Sanchez available as well, but Williams wanted Strasburg to decide his own fate. With first base open, Williams opted to intentionally walk Snider – who was 1 for 4 against left-handed pitches – and bring Harrison to the plate.

Ross Detwiler has struggled in the bullpen this season after losing his spot in the Nationals’ starting rotation. The Post Sports Live crew offers advice on what to do with the hard-throwing left-hander. (Post Sports Live/The Washington Post)

“We were going to be careful there,” Williams said. “He’d pitched well to Harrison all night. And we don’t want to get in a situation where he falls behind and has to throw a fastball to Snider. You just set up the forceout.”

Like Williams, the Nationals wanted Strasburg on the mound.

“Everybody felt good about him staying in there,” Werth said. “It looked like [Harrison] hit a pretty good pitch. You like that matchup there. You’re giving him a chance to win the game. I thought he pitched great tonight.”

Strasburg fell behind Harrison with a fastball. He followed with a change-up, his best pitch — he had allowed only one hit on it all night. Harrison ripped a grounder past the mound and through the middle.

“Just hit it where we weren’t,” Strasburg said. “Free swinger. He’s going to put the ball in play. He hit it up the middle.”

Marte raced home to score, touching the plate before Denard Span’s throw retired Snider at third base.

Strasburg, the first overall pick in the 2009 draft, opposed Cole, the top selection in 2011. First draft choices had only met 11 times since the draft began in 1965, and not since David Price squared off vs. Luke Hochevar in 2012. It had last happened in the National League when Paul Wilson faced Kris Benson in 2005.

The right-handers dominated the game’s first three innings.

Cole blinked first. Strasburg’s change-up borders on art; Cole’s is closer to an experiment. With one out in the first, Cole tried to sneak one past Ian Desmond, who sent it three rows deep to left-center field, 404 feet from home plate. The Nationals led, 1-0.

As Strasburg retired the first 10 batters he faced, dotting corners with his fastball, ditching problems he had earlier this year with fastball command. But with a 1-1 count on Neil Walker in the fourth, Strasburg fired a fastball at the top of strike zone that bisected the plate. Walker belted it over the center field fence and into the Nationals’ bullpen, tying the score at 1.

The Nationals seized the lead right back after Anthony Rendon smoked a single to left and sparked a two-out rally. After Werth walked, Wilson Ramos blooped an RBI single to right field, the Nationals’ first run-scoring hit with a runner in scoring position since Tuesday.

“We’re in one of those stretches offensively where it’s not going right,” Williams said. “We had created some opportunities again for ourselves tonight, stealing some bases and getting guys out there. But it didn’t happen.”