Jonathan Huberdeau scored two goals, Evgenii Dadonov had a goal and two assists and Roberto Luongo made 28 saves for Florida (34-32-12), which won for the first time in four games.
"We weren't too happy with ourselves the last few games," Luongo said. "We got embarrassed in a few of them. We had a good test tonight and we knew that we had to show up and play hard, and if we did that we liked our chances."
Brady Tkachuk scored his 20th goal of the season, and Anders Nilsson made 29 saves for the Senators (27-44-6).
"[Battling back] has been kind of our motto," Tkachuk said. "And what we've shown is that we're never out of it. We're always in it. We never give up. We're always playing for one another. Like I've said, that's what makes it fun to come to the rink with this group because everyone's going to be working for one another and putting their heart on the line. It's pretty disappointing tonight, but it's a chance to learn and use it moving forward."
The Panthers and Senators each have already been eliminated from Stanley Cup Playoff contention.
Barkov's wrist shot deflected off Dadonov's shin pad to give the Panthers a 1-0 lead 30 seconds into the first period.
Colin White deked Florida defenseman Aaron Ekblad at the blue line and then chipped the puck into the top right corner to tie it 1-1 at 12:59.
Troy Brouwer backhanded a rebound in at the edge of the crease to give Florida a 2-1 lead at 2:35 of the second period. Huberdeau accepted a cross-slot pass on his backhand and finished on his forehand into an open net to make it 3-1 at 6:31.
Tkachuk chipped a backhand shot over the outstretched glove of Luongo to cut it to 3-2 at 3:01 of the third period. Tkachuk tied a Senators single-game record with 12 shots, set by defenseman Jason York on Jan. 30, 1999.
"[Coach Marc Crawford's] mentality is the more shots you take, the more chance you have of the puck going in," Tkachuk said. "That was the goal coming back from Christmas and the All-Star break. They wanted me to get to 20 [goals]."
Dryden Hunt scored into an empty net to make it 4-2 at 18:32, and Huberdeau scored at 19:46 for the 5-2 final.