BOSTON — It was an emotional start to the game for the Boston Red Sox and Kansas City Royals Saturday, as a pre-game ceremony honored the victims of this week’s terrorist attacks in Boston, along with the first responders who helped treat the victims and law enforcement who captured the suspects.

And it was a dramatic ending, as Daniel Nava’s two-out, three-run home run in the eighth inning gave the Red Sox a 4-3 victory.

Clay Buchholz earned the win to improve to 4-0, going eight innings, giving up two runs on eight hits with no walks and six strikeouts.

“A fantastic finish to a great day,” Red Sox manager John Farrell said. “From the tribute before the game, the many that were acknowledged, to the way we went out and played.

“I thought Clay once again, just an outstanding performance on his part. A couple of big double plays. Nava not only a key moment, but a huge hit when we’re down a run.

“And I thought overall, even though we didn’t have a whole lot to show for it on the board, we had a very good approach against (Royals starter James) Shields, who was good today, to work up his pitch count, to get him out of the game after the sixth.”

The Royals got on the board first as Lorenzo Cain led off the fifth with a double off Buchholz. Jeff Francouer’s one-out single to left put the Royals up, 1-0.

But the Red Sox tied the game in the sixth when Jacoby Ellsbury led off with a single off Shields, took second on Shane Victorino’s sacrifice bunt and third on Dustin Pedroia’s groundout.

David Ortiz’s single to center scored Ellsbury.

The Royals got another run in the seventh when Cain led off with a double and scored on Salvador Perez’s two-out triple.

Nava’s home run, his fourth of the season, scored Jonny Gomes, who opened the inning with a pinch-hit double, and Pedroia, who walked.

“I wasn’t running the bases thinking about everything (that happened before the game),” Nava said. “I was thinking about the significance of us coming back late in the game, how much adrenaline you got. After that I started to think about, ‘Hey, wait a minute, everything that this day means.’

“A home run or winning a game is obviously nice but the people that lost their lives and stuff like that, a home run doesn’t bring the people that they lost back. So I think maybe getting a win at least maybe takes their mind off of it just for a split second or two. And if we can do that, that’s something we try to do.”

Ortiz made his season debut after beginning the season on the disabled list because of Achilles and heel ailments. In his first game since Aug. 24, also against the Royals, he went 2-for-4 with a run batted in.

“This was one of those games everybody had a lot of emotion going on from the very beginning, with the ceremony, to finish up a game like that you just get everybody in a great mood,” Ortiz said.

“One thing I’ve been thinking about all week is how the families have been affected by this situation. … Winning this game and watching Nava winning the game, I’m sure we have a lot of people forgetting what happened the past week. You get people in a good mood, give them some hope. We want to let them know we are here for them.”

Shields went six innings, giving up one run on four hits and three walks with eight strikeouts, but was not involved in the decision.

“He struggled to find his control a little, which got his pitch count up,” Royals manager Ned Yost said.

Andrew Bailey earned the save, his third, despite giving up a lead-off home run to Cain in the ninth. Cain went 4-for-4 with a home run, two doubles, an RBI, and three runs. He raised his average from .340 to .392.

“At the end of the day we didn’t get the win, so it was tough to enjoy it,” Cain said. “It was a good day at the plate for me, but we didn’t come up with the win, which was the most important part.”

Kelvin Herrera (1-2) was charged with a blown save and the loss, going one-third of an inning, giving up two runs, including Nava’s home run.

NOTES: The Royals’ first run of the game, with one out in the fifth inning, snapped a 22-inning scoreless streak for Clay Buchholz. … In their 16th game of the season, the Red Sox had faced an opponent with a record above .500 for the first time. … The Red Sox extended their winning streak to seven games, their longest since nine games from June 3-12, 2011. … The Red Sox are eight games over .500 for the first time since the end of the 2011 season. … The Royals have lost four of their last six games since starting the season 6-3, and they are 10-23 at Fenway Park since the start of the 2005 season. … Stephen Drew snapped an 0-for-9 skid with a fifth-inning single. … With his first-inning walk, Dustin Pedroia has reached base safely in all 16 games this season. He also extended his streak of reaching base safely to 26 games since Sept. 21, 2012. It is the third-longest such streak of his career, behind the 37 in 2011 and the 29 in 2008. … Shane Victorino left the game because of low back tightness. … James Shields is 1-0 with a 0.63 ERA in his last two starts at Fenway Park after posting a 1-9 record with a 6.75 ERA in the first 10 starts of his career in Boston, all with Tampa Bay. This was his first career outing at Fenway without a decision, snapping a stretch of 11 in a row.