It looked as if Swansea, who had Wilfried Bony sent off in the 39th minute, would hold out for a point.
But, 10 minutes from time, Kenya midfielder Wanyama’s angled finish secured victory for the Saints and left the south coast club two points behind Chelsea ahead of the leaders’ match at champions Manchester City on Sunday.
Ivory Coast striker Bony was shown a first red card in English football with a reckless tackle from behind on Saints defender Maya Yoshida.
Bony had already been booked for catching Jose Fonte in mid-air after 20 minutes and, while that might have ben a questionable yellow card, the second booking was beyond dispute.
Swansea had been on top until Bony’s dismissal, but his exit changed the course of the match, with Southampton on top for most of the second half in south Wales.
Even so, they had to wait until the 80th minute to break the deadlock when Italian striker Graziano Pelle set up Wanyama, who finished confidently to give Ronald Koeman’s Southampton side their third consecutive victory.
With England manager Roy Hodgson among the spectators at the Liberty Stadium, Swansea made a positive start.
Swansea’s Gylfi Sigurdsson fired straight at England goalkeeper Fraser Forster before the Swans’ Wayne Routledge volleyed wide.
The home side nearly took a 28th-minute lead when Sigurdsson found Routledge, only for the winger’s shot to hit the top of the crossbar.
Bony also went close, his header from a Sigurdsson corner cleared off the line by Saints left-back Ryan Bertrand.
But then came Bony’s red card and Southampton took charge.
Pelle had a header tipped over the bar by former Arsenal keeper Lukasz Fabianski and then had an even better chance when, unmarked, he headed wide from 10 yards out following a Steven Davis cross.
But fortunately for Southampton, it was not a decisive miss and Pelle made amends with his pass to Wanyama for the all-important goal.