The visitors have lost their last five games in the league and are now at the foot of the table.
James Ward-Prowse's second-half free-kick looked to have secured a point for his side.
Kenny Tete's flick-on set up Palhinha's 88th minute goal.
The chance to add to the score came and went.
They have won four in a row and moved up to seventh.
The hosts remembered one of their own before the game started.
Marco Silva laid a wreath around the center circle in memory of the 1966 World Cup winner, who died at the age of 83.
Cohen was a part of the ground staff at the Whites before embarking on a one club career. The fans chanted the former full-back's name after a minute's applause.
When Che Adams darted behind the high line, Leno did a good job of repelling his attempt.
Mohamed Elyounoussi skimmed a shot narrowly over the bar, but the Cottagers gradually asserted themselves in the middle of the park, and were rewarded with a goal on the 32nd minute.
Willian clipped a corner to the edge of the penalty area. The volley was well-struck but seemed to be heading off target until Ward-Prowse blocked it.
Only David Beckham and James Ward-Prowse have scored more free-kick goals in the league this season.
The 28-year-old captain whipped a superb swirling free- kick around the wall and beyond Leno's dive to cancel out his own- goal and level the contest.
The scores were equal before the contest got going in the last few minutes.
Tom and Willian tried to set up Pereira at one end, but Romain Perraud tried to stop them.
The hosts went ahead again when another set piece isolated Palhinha, who is 6ft 3in tall, against a group of smaller defenders.
The Serbian had a chance to add to his goal tally after a foul on Dan James. A quiet afternoon for the Serbian strikers came to an end when he missed his penalty.