Nick Seeler had three assists, and Aleksei Kolosov made 24 saves in his first appearance since Jan. 2 for the Flyers (32-37-9), who have already been eliminated from playoff contention.
"It was pretty wild," Couturier said. "Not sure it's the kind of period that both teams want to play or expected, but sometimes that's how it goes. Just got to find a way."
Mika Zibanejad had four assists and Jonathan Quick made 22 saves, but the Rangers (36-35-7) lost their third straight game and remain eight points behind the Montreal Canadiens for the second wild card into the Stanley Cup Playoffs from the Eastern Conference.
New York and Montreal each have four games remaining. The Rangers would be eliminated from playoff contention with a loss of any kind against the New York Islanders at UBS Arena on Thursday.
"It's a [bad] feeling in here for sure," Rangers defenseman Adam Fox said. "We're hanging on by a thread at this point. But show up tomorrow and try to win a game. That's pretty much all we can do right now."
Vincent Trocheck's short-handed breakaway goal at 11:33 of the first period gave the Rangers a 1-0 lead.
Foerster tied it 1-1 at 9:03 of the second period, scoring with a wrist shot from the top of the left face-off circle.
Garnet Hathaway's short-handed goal at 16:43 gave the Flyers a 2-1 lead.
Artemi Panarin tied it 2-2 at 18:32, taking a drop pass from Zibanejad, carrying the puck through the right circle, deking to his backhand and roofing a shot into the top left corner.
It was Panarin's 300th NHL goal. He's the only active undrafted player to score at least 300 goals.
"I don't think anybody thought it was going to end up 8-5 after two periods," Shaw said, "but sometimes those periods just sort of have a life of their own and that's where it ended up."
The third started with Sanheim giving the Flyers a 3-2 lead at 3:05.
He grabbed the puck below the goal line to the right of the net, pulled it to his forehand and put it in before Quick had time to recover after making an initial save on Cates at the left post.
The Rangers tied it 3-3 at 5:38 on Brodzinski's shot from left side that deflected off Karsen Dorwart's stick.
Miller made it 4-3 Rangers at 7:01, scoring with a one-timer from the top of the right circle off a 3-on-2 rush with Zibanejad and Will Cuylle.