BOSTON — The hottest pitching staff in baseball slowed down the best offense in baseball Friday night.

The Kansas City Royals, who boast the best ERA in the majors in August, held the Boston Red Sox at bay, and the Kansas City bullpen extended its franchise-record scoreless-innings streak to 42 innings before a ninth-inning hiccup in a 6-3 win at Fenway Park.

Starter Ian Kennedy (9-9) earned the win for the Royals (67-61), who have won 11 of their past 12 games and 16 of their past 19. The Royals had a 1.19 ERA in their past 10 games and a 2.26 ERA in August before Friday.

Kennedy’s streak of five straight starts going at least six innings and allowing one or no runs ended, but he was still strong against the Red Sox. Kennedy went 5 1/3 innings, allowed two runs on nine hits and struck out eight while walking two and throwing 107 pitches (68 strikes).

Chris Young, Brian Flynn, Peter Moylan and Kelvin Herrera closed out the victory, although Moylan was charged with a run in the ninth inning.

Eric Hosmer, Alex Gordon and Lorenzo Cain all hit home runs as part of the Royals nine-hit attack.

Dustin Pedroia went 4-for-4 with one RBI and Mookie Betts went 5-for-5 with two RBIs, but the Red Sox (71-57), who lead baseball in runs scored and most other major offensive categories, left 12 men on base and lost their third straight.

Boston starter Steven Wright (13-6) put the Red Sox in a 5-0 hole in the top of the first inning but rebounded with five shutout innings in his first start since Aug. 5. Wright, who had been on the disabled list before Friday, finished with five runs allowed on seven hits in six innings.

In the bottom of the ninth inning Pedroia and Xander Bogaerts greeted Moylan with back-to-back singles. Herrera entered and got David Ortiz to ground into a double play. Betts followed with a RBI single to end the Kansas City bullpen’s scoreless streak and cut the lead to 6-3.

Hanley Ramirez followed with a single to set up runners on the corners before he took second on defensive indifference. Sandy Leon grounded out to second base to end the game.

Wright hadn’t allowed two home runs in a game all season, but surrendered two in the first inning to the Royals. The night started with walks to two of the first three Kansas City batters. Hosmer then hit a 2-1 knuckleball into the Monster seats for a 3-0 lead.

Kendrys Morales followed up with a single and Gordon hit a 1-0 knuckleball into the Monster seats to make it 5-0.

The Red Sox scored once in the bottom of the first, but Kennedy limited the damage. Betts singled with two men on to plate one run with one out and a walk to Ramirez loaded the bases. Kennedy caught Leon looking and fanned Jackie Bradley Jr. after the count ran full to escape further trouble.

Kennedy put out another Red Sox threat in the third after there were runners on first and third with no outs. He coaxed Ramirez to pop out and again struck out Leon and Bradley (both swinging).

The Red Sox left two more men on base in the fourth and wasted a Betts leadoff single in the fifth.

The Sox knocked out Kennedy with one out in the bottom of the sixth, when Brock Holt doubled. Young relieved Kennedy and surrendered an RBI single to Pedroia to cut the Kansas City lead to 5-2. But Young got out of the inning without further damage.

Cain hit the Royals’ third home run leading off the top of the eighth against relieve Junichi Tazawa for a 6-2 lead.

NOTES: OF Andrew Benintendi, who was placed on the disabled list because of a knee injury he suffered running the bases Wednesday against the Tampa Bay Rays, went through a number of tests Friday. Manager John Farrell said the tests revealed no structural damage and just a sprained left knee. There is a chance Benintendi could return to the Red Sox lineup before the end of the regular season. … The Red Sox activated RHP Steven Wright from the disabled list prior to the game, and he started Friday. To make room on the roster they optioned RHP Heath Hembree to Triple-A Pawtucket. Hembree is 4-1 with a 2.40 ERA in 41 1/3 innings this season. … With Wright back, RHP Clay Buchholz has been shifted to the bullpen. The right-hander allowed two earned runs over 12 1/3 innings in two spot starts before Wright’s return. …RHP Koji Uehara, who has been on the DL since July 20 with a right pectoral strain, threw a 50-pitch bullpen session Friday. … Royals manager Ned Yost said RHP Wade Davis, who has been on the DL since July 31 (retroactive to July 28) with a flexor strain, will pitch on a rehab assignment for Triple-A Omaha on Saturday and probably again Monday. But Yost doesn’t expect the closer to return before Sept. 1. … Royals C Salvador Perez had a planned day off Friday. Perez was 2-for-12 during the Royals’ three-game series against the Miami Marlins this week.