BOSTON – John Lackey can appreciate his teammates’ offense even more with the struggles he’s gone through this season.

David Ortiz hit a grand slam to cap a five-run fourth inning, and Dustin Pedroia extended his career-best hitting streak to 24 games with a solo homer, carrying the Boston Red Sox to a 12-5 victory over the Kansas City Royals on Wednesday night.

Jacoby Ellsbury homered leading off the first inning and Pedroia followed with his homer for the Red Sox, who won for the 19th time in 23 games and scored in double digits for the second straight game.

“That’s one of the reasons I came here,” Lackey said when asked what it’s like watching Boston’s offense hitting the way it has been recently. “I didn’t get a lot of that in Anaheim. Jacoby’s having a great season, he’s getting a little of everything, and (Pedroia) is on fire.”

Pedroia, who went 4 for 5 in Tuesday’s 13-9 win, added two singles and a sacrifice fly, Ellsbury had three hits to increase his average to .325, and Adrian Gonzalez had three hits and three RBI to raise his major league-leading total to 87.

Lackey (9-8) won his fourth straight start, allowing four runs — three earned — and 11 hits, walking one and striking out three in 52/3 innings. The Red Sox scored six and seven runs, respectively, in his previous two starts.

“I don’t think anybody would complain about sitting around and watching guys score runs,” he said.

Eric Hosmer hit a three-run homer and Billy Butler added a solo shot for the Royals.

As in Tuesday’s loss, Kansas City blew an early lead. After Hosmer’s homer put the Royals up 3-0 in the first, Boston scored twice in the bottom of the inning and three in the second before breaking it open in the fourth against starter Bruce Chen (5-4).

Boston had 16 hits, reaching double digits for the 11th straight home game.

Ellsbury’s home run caromed off the foul pole in right and Pedroia hit his into the Green Monster seats in left, extending his career-best streak, the longest by a second baseman in club history.

“We started out in the game and we’re down 3-0 and that’s not an easy way to play,” Boston Manager Terry Francona said. “We get the two home runs and ‘OK, we’re right back.’“

In the second, Ellsbury drew a bases-loaded walk, Pedroia had a sacrifice fly and Gonzalez’s run-scoring grounder made it 5-3.

The Red Sox broke it open with the five-run fourth highlighted by Ortiz’s slam. Pedroia, Gonzalez and Kevin Youkilis singled before Ortiz belted his 10th career slam — ninth with the Red Sox — over Boston’s bullpen, tying him with Rico Petrocelli for second in club history behind Ted Williams’ 17.

Yamaico Navarro had an RBI single earlier in the inning.