Pastrnak and Linus Ullmark (30 saves) each returned for Boston (48-25-5), which moved two points ahead of the Washington Capitals for the first wild card.
The Bruins also remained three points behind the Tampa Bay Lightning for third in Atlantic Division. Tampa Bay defeated the Nashville Predators 6-2 later on Saturday.
"I was just out for like a week, so I wasn't worried at all [about rust]," said Ullmark, who missed three games with a lower-body injury. "I thought the boys in front did a terrific job in front, keeping me on my toes and helping me out there in the beginning. Obviously, there's going to be some small rustiness, but when you get [good] looks in the beginning, it's long gone."
Mika Zibanejad scored, and Igor Shesterkin made 32 saves for New York (51-22-6), which fell two points behind the Carolina Hurricanes for first in the Metropolitan.
"I think the game went back and forth," Rangers forward Barclay Goodrow said. "… Their goalie made some good saves, but overall it was a pretty good game. Obviously, they're preparing for the playoffs, just like we are. So it was good to play one of those teams, and have a close hockey game. I think we did a lot of good things, and there are obviously some things we could have done better; little mistakes that cost us."
Pastrnak, who missed eight games with an undisclosed injury, put the Bruins ahead 1-0 with 35 seconds remaining in the first with a one-timer on a no-look pass from Charlie McAvoy off the rush.