NEW YORK — The New York Rangers are suddenly rolling thanks to timely scoring and tight defense, especially the brand exhibited against Boston on Wednesday night.

Jimmy Vesey scored two first-period goals 29 seconds apart, Henrik Lundqvist made 31 saves and New York beat the Bruins 4-2 for its fifth straight victory.

Pavel Buchnevich and Rick Nash also scored for the resurgent Rangers, who improved to 8-7-2 despite losing seven of their first eight games.

“We’re moving in the right direction,” Lundqvist said after his seventh win this season and the 412th of his career. “We’re back in the race.”

David Pastrnak and Patrice Bergeron had the goals for Boston.

The Rangers came out strong against their old rivals, outshooting the Bruins 16-7 in the opening period and scoring three times. Boston had the better of play in a scoreless second, with a 13-8 shots advantage.

New York led 3-1 heading into the third period before Bergeron cut the margin to one at 6:44 with his third goal of the season. Lundqvist was able to hold off the Bruins before Nash scored into an empty net with 7.7 seconds left.

“When you get a lead, you have to know how to play. I thought we were pretty smart with the puck,” Rangers defenseman Marc Staal said. “We are confident. We have to keep on working and keep grabbing points when we are on a roll like this.”

Buchnevich opened the scoring at 9:53 of the first with his seventh of the season, but Pastrnak quickly tied it at 10:14. Pastrnak’s team-leading ninth goal was assisted by Bergeron and rookie Anders Bjork.

Vesey, who played four years at Harvard, then jammed a loose puck past Bruins netminder Tuukka Rask at 14:41, with assists from Buchnevich and Mika Zibanejad, to put the Rangers ahead 2-1.

Vesey increased the lead at 15:10 when he slid another close-in shot past Rask for his fourth of the season. It was the fastest two goals by a Rangers player since Jaromir Jagr scored twice in 26 seconds on Nov. 14, 2006.

“I consider myself a goal scorer. I’ve done that my whole life,” Vesey said. “I got a couple of greasy ones tonight. Maybe it will take off from here.”

The 24-year-old Vesey had six game-winning goals among the 16 he scored as a rookie last season. He had only two goals this season going into the game against his hometown Bruins (6-5-3).

Boston played without top forward Brad Marchand, who sustained an upper-body injury in the previous game.

The Bruins’ lineup included several recent call-ups from Providence of the AHL, and coach Bruce Cassidy wasn’t happy with his team’s start.

“The first part of the game we had some passengers. We are not going to win on a regular basis if we have passengers,” he said. “We don’t need young guys to come in here and lead this club. We just need them to do their jobs.”

The goal by Buchnevich was his seventh of the season and came after he eluded 40-year-old Bruins defenseman Zdeno Chara and roofed the puck over Rask. The Russian forward has been on an offensive spree lately with six goals and three assists in his last seven games.

“We weren’t playing on our toes,” Chara said. “The Rangers were more aggressive. We need to do a better job.”

The Rangers have won seven of nine since a 1-5-2 start to the season. They were trailing expansion Vegas 4-2 at home heading into the third period Oct. 31 but scored four unanswered goals to win 6-4. Then they defeated Tampa Bay and Florida in overtime on the road before returning home to beat Columbus on Monday.

“We’ve been starting games a lot better and it’s been working for us,” Vesey. “Now we have five in a row.”

The Rangers have 256 wins over the Bruins, the most against any opponent in their 91-season history, and have won six straight versus Boston since January 2016.

NOTES: Alain Vigneault earned his 200th win as Rangers coach. The only other New York bench bosses to reach the milestone are Emile Francis (342) and Lester Patrick (281). … Rangers forward Mats Zuccarello played his 400th NHL game. … Chara played his 834th game with the Bruins, passing Hall of Famer Dit Clapper for fourth-most by a Boston defenseman. … The Rangers scratched high-priced defenseman Brendan Smith for the fourth straight game.


The Bruins visit Toronto on Friday.

The Rangers host Edmonton on Saturday.