Bryce Harper had three hits and drove in three runs, and a beleaguered bullpen held on as the Washington Nationals snapped a four-game losing streak with a 5-4 victory over the St. Louis Cardinals on Thursday night.

The Nationals won for just the third time in their last 10 games and snapped the Cardinals' season-high, eight-game winning streak.

Tanner Roark (8-12) gave up four runs, three earned, in six innings.

A bullpen that had blown two leads to start the losing streak took care of the rest. Justin Miller pitched two scoreless innings and Koda Glover earned the save in the first opportunity since Ryan Madson was placed on the disabled list on Tuesday.

Harper drove in the game's first run with a double in the first and knocked in two more with a bases-loaded single in the fourth to give the Nationals a 4-1 lead.

A pair of errors helped the Nationals extend their lead to 5-1 in the fifth. St. Louis committed three errors in the game after committing just four total errors during the winning streak.

The Cardinals got within one in the sixth. After Paul DeJong and Kolten Wong came up with back-to-back, two-out RBI hits, Harrison Bader hit a slow grounder to third. Anthony Rendon's throw to first got away from Ryan Zimmerman for an error, allowing Wong to score from second to cut the Nationals' lead to 5-4.

Just two of the four runs Luke Weaver (6-11) allowed in his 3 2/3 innings were earned. He gave up seven hits, including two to Roark, who scored both times.

Tyson Ross allowed one unearned run in 3 1/3 innings of relief.

Bader homered in the third and Matt Carpenter walked in the third to extend his on-base streak to a career-high 34 games.

TRAINING ROOM

Nationals: RHP Jeremy Hellickson will have an MRI on his sore right wrist on Friday. RHP Joe Ross (right elbow surgery) threw 3 2/3 scoreless innings at Class A Potomac on Thursday and is hoping for a September return.

Cardinals: RHP Carlos Martinez (right shoulder strain) will begin a rehab Friday at Double-A Springfield. RHP Adam Wainwright (right elbow inflammation) threw two scoreless innings Thursday night at High-A Palm Beach.

UP NEXT

Nationals: RHP Max Scherzer (15-5, 2.19 ERA) will take the mound as the Nationals return home for a three-game series Friday night against the Miami Marlins and RHP Dan Straily (4-5, 4.42 ERA). Scherzer is 3-0 with a 3.43 ERA in three starts this season against the Marlins.

Cardinals: RHP Jack Flaherty (6-6, 3.22 ERA) kicks off a three-game series Friday night as the Cardinals host the Milwaukee Brewers and RHP Freddy Peralta (5-3, 4.47 ERA). Flaherty struck out a career-high 13 batters in his last start against the Brewers on June 22.