BOSTON — There were moments when it appeared the Braves might fade to yet another loss. Instead, they kept competing until they finally won another game.

The Braves beat the Red Sox 5-3 on Thursday at Fenway Park to end their losing streak at eight games. Veteran Nick Markakis had three RBIs and rookie Mallex Smith had two as the Braves (5-17) beat up Red Sox starter Clay Buchholz.

“We did a lot of good stuff the whole game pitching-wise, offensively,” Braves manager Fredi Gonzalez said. “It’s a good baseball game.”

Braves starter Jhoulys Chacin allowed two runs over five-plus innings before five relief pitchers combined to limit the Red Sox (12-10) to one run the rest of the way. Chacin got off to a shaky start and allowed seven base runners through the first three innings but limited the damage to two RBIs by Hanley Ramirez.

Chacin went to spring training on a minor-league contract as one of several candidates to join the Braves’ rotation. He’s turned out to be their most effective pitcher early in the season with a 3.27 ERA through four starts.

Shoulder issues slowed Chacin during the past two seasons but he appears to be rounded into the form he showed while having a career-best season with the Rockies in 2014.

“I feel fine,” Chacin said. “My arm feels good. Everything is getting back to where it used to be before. I just want to keep going and trying to give the team the most I can (and) trying to maybe go a little bit longer in games.”

Buchholz walked four batters and allowed eight hits and five runs over 6 1/3 innings. The Braves took a 5-2 lead on Smith’s run-scoring single in the sixth inning.

Ramirez led off the bottom of the sixth with a single that chased Chacin in favor of left-hander Eric O’Flaherty. O’Flaherty got Travis Shaw to ground into a double play and, after Chris Young followed with a double, struck out Jackie Bradley Jr. to end the inning.

After the Braves left the bases loaded in the top of the seventh inning, Christian Vazquez led off the bottom of the inning with a single against Alexi Ogando. Mookie Betts followed with a walk but Ogando retired Dustin Pedroia on a fly out and stuck out Xander Bogaerts.

Braves left-hander Hunter Cervenka came in to face Red Sox slugger David Ortiz, who grounded out.

“How many left-handed relievers do you think ‘Big Papi’ has faced in his career in the seventh, eighth, ninth innings?” Gonzalez said of Ortiz. “And I mean good relivers. He’s facing your best left-handed relievers all of his career. Cervenka got him out but I wasn’t too comfortable with that because of what he’s been able to do.”

Ramirez staked Buchholz to a 1-0 lead with an RBI single in the first inning. The Braves responded in the second inning with Smith’s RBI double and a two-run single by Markakis that put them ahead for good.