The Nationals’ Nate McLouth, left, is safe at first as he beats Cardinals first baseman Matt Adams to the bag as pitcher Jaime Garcia watches in the fifth inning. (Jeff Roberson/AP)

As the Washington Nationals have gone from bottom-dwellers to contenders over the past two-plus seasons, they have written new histories with opponents. But one of the few teams they cannot seem to solve, no matter the circumstances, is the St. Louis Cardinals.

The Nationals arrived in St. Louis on Friday for the final leg of an exhausting 10-day road trip playing their best baseball of the season. They had won of 10 of their previous 13 games, including five of seven in San Diego and San Francisco. They left St. Louis with three deflating losses, punctuated by Sunday’s 5-2 defeat.

Some of the good feeling of the Nationals’ early June turnaround evaporated in the sweep. Since 2008, the Nationals are 2-18 in St. Louis. And since the start of the 2012 season — including that year’s National League Division Series loss — the Nationals are 8-17 against the Cardinals.

“I don’t know what it is,” Ryan Zimmerman said. “You go year by year, and some years you do well against some teams and some years you don’t. Not going to take anything away from them. They’re a really good team.”

If the Nationals hope to rise to the top of their division and league, they must learn to solve the NL’s most accomplished teams. Their four-game losing streak has dropped them one game out of first place in the NL East. Their 5-5 road trip fluctuated from exhilaration to frustration.

“We have a bitter taste in our mouth going home,” left fielder Scott Hairston said. “We definitely played not to our capabilities and didn’t take advantage of opportunities we had.”

“You go through this road trip the way we went through it, and it’s okay,” Manager Matt Williams added. “Could have been better. We came out of it all right. Guys are tired. The off-day will come at a good time after going west and a long road trip.”

The Cardinals have a solid starting rotation, but the Nationals’ offensive halt has been abrupt and damaging. Including the final game in San Francisco, the Nationals have scored four runs in four games. In the previous six games, they scored 32. Against St. Louis, the Nationals stranded 18 base runners and went 2 for 13 with runners in scoring position.

“That can’t happen,” Hairston said. The problem wasn’t only a lack of scoring but a scarcity of chances.

“It’s the ebbs and flows of the game. It’s that time of year where heavy legs start to set in a little bit,” Williams said. “The off-day will come at a good time for us. It’s the way it goes sometimes. The offense on the first two stops was pretty good, and this stop wasn’t so good. We’ll regroup and get ready to go.”

The Nationals tweaked their lineup against left-hander Jaime Garcia. Zimmerman made his debut at first base, and Adam LaRoche was given a day off since he has struggled against Garcia. As a result, the right-handed hitting Hairston started in left field, where Zimmerman had been playing.

The Nationals have had some success against Garcia, hitting .295 with a .350 on-base percentage and a .375 slugging percentage against him in his five career starts against them. The Nationals also have crushed left-handers this season, posting a .760 OPS, baseball’s sixth-best mark.

Some Nationals, such as Zimmerman and Hairston, hit the ball hard but right at well-placed defenders. Some made mistakes; Hairston settled for a second-inning single on a ball he hit off the left field wall because he jogged out of the batter’s box thinking it was a home run.

“I was caught up in the moment and wasn’t trying to show anybody up,” Hairston said. “Just hit it and hoped it would go out and got caught looking at it. Next time I’ll look down and just run and let everything take care of itself.”

The Nationals’ improvement in June had been powered by hot-hitting and dominant starting pitching. For the most part, the starters held their own against the Cardinals. Doug Fister, who entered with a 1.83 ERA over his previous six starts, had his first shaky start in weeks.

Fister thrives by walking few batters and having opponents beat his sinker into the ground. In his previous 391 / 3 innings, he walked only three batters. On Sunday, he walked two in six innings. He also left pitches up in the strike zone, and the Cardinals clobbered them.

Matt Adams homered in his third straight game, crushing a Fister cutter over the right field fence in the second inning for a two-run homer. His supremacy over the Nationals’ pitching earned him a curtain call.

Fister served up another home run in the third inning, a laser shot by Matt Holliday that gave the Cardinals a 3-1 lead.

Fister allowed another run in the fifth inning, and reliever Ross Detwiler gave up one in the seventh.

“It’s always frustrating to walk a guy, but the two home runs were the two biggest things for me — and the sac fly,” Fister said. “Those are pitches I need to execute better.”

The Nationals created a measure of drama in the ninth inning by loading the bases against Sam Freeman and closer Trevor Rosenthal. LaRoche drove in a run with a walk as a pinch hitter, but Jayson Werth popped up to end the game.

“We’d like to do better here, but we put ourselves in a good position,” Zimmerman said. “West Coast, play four in San Francisco, and .500 is good. We expect more of ourselves. But with the length of the road trip and the teams we’ve played, it could always be worse.”