McAvoy, a Long Beach, New York native, scored his first goal in five games at MSG.
"It was really cool," he said. "Growing up and being a big fan of the Rangers and going to games here and everything, that's special. It's been fun coming and playing here and we've had pretty good success."
WATCH: [All Bruins vs. Rangers highlights]
Charlie Coyle and Patrice Bergeron scored, and Jaroslav Halak made 25 saves for the Bruins (37-11-12), who have won three straight games.
"We're playing really good hockey right now," Bruins forward Brad Marchand said. "It just seems like everybody has kind of found chemistry on their lines and kind of knows where to fit in and we have a healthy team."
Mika Zibanejad scored, and Alexandar Georgiev made 31 saves for the Rangers (30-24-4), who had their four-game winning streak end.
"I think we were pretty confident going into this game," Georgiev said. "Obviously tight game today, we had a good battle with Boston and we just have to learn from it and keep playing the way we've been playing."
McAvoy gave the Bruins a 1-0 lead at 19:18 of the first period when his point shot deflected off Rangers defenseman Jacob Trouba, popped into the air and past Georgiev's glove. It was McAvoy's third goal in six games after going the first 51 games of the season without one.
"It was nice to see that one go in. I thought it was [Chris Wagner's] goal 100 percent. He did a good job, he went to a hard area and I tried to shoot for his stick. Was lucky enough to get a good bounce and that was a big goal for us to get on the board first."
Rangers coach David Quinn said, "That first goal is a kick in the [rear end] that we give up that drops out of the sky. Could feel it in the locker room that guys were a little deflated and I don't think we responded very well."
Coyle gave the Bruins a 2-0 lead at 18:42 of the second period with a shorthanded breakaway goal.