Juan Mata’s close-range strike just after half-time put United ahead, but Ayew and Gomis gave Swansea a victory which moved them above the Red Devils and into the top four of the Barclays Premier League.
Gomis had scored the winner when the two sides last met in February, part of a Swansea double, and he did so again with his fourth goal of the season and his ninth in the last 10 Premier League games.
It all added up to another feather in the cap of Swansea manager Garry Monk and a desperate afternoon for Louis van Gaal, who was taking charge of United for the 50th time, and saw his side concede for the first time in the league this season.
United had scored four times in the Champions League in midweek and they started where they left off in Bruges, full of attacking intent and trying to get the ball into lone striker Wayne Rooney quickly.
Memphis Depay won a second-minute free-kick which he took and forced Luakasz Fabianski into a scrambling save on his goal-line and Mata was almost instantly off target from 20 yards.
Luke Shaw then released Rooney with a peach of a pass which cut out Federico Fernandez but Ashley Williams covered brilliantly to avert the danger.
United were at their most dangerous when Memphis was drifting off the left flank and from one such foray he picked out Herrera, but Mata was unable to profit from his fellow Spaniard’s pass as he fired wide of the near post.
Swansea had been slow to stir with some of their early-season attacking fluency denied them by the absence of thigh injury victim Jefferson Montero.
But the hosts suddenly took a grip of the game at the halfway point of the first half after Gomis had raced onto Ayew’s pass to shoot wide.
Seconds later Gomis’ clever flick freed Gylfi Sigurdsson and the resulting snapshot was inches wide of the post.
But United were clearly rattled and Sergio Romero’s poor clearance straight at Jonjo Shelvey ended with the goalkeeper having to clutch the midfielder’s shot under his crossbar.
Swansea were even closer to breaking the deadlock after 28 minutes when Gomis’ purposeful run left Daley Blind and Chris Smalling struggling to cope and the Frenchman poked the ball against the outside of Romero’s post.
But United were ahead when Shaw surged down the left and his cross fell to Mata at the far post who crashed the ball high into the net under pressure from Williams.
Mata might have had another but Swansea equalised from a 61st-minute counter-attack when Williams fed Sigurdsson and Ayew’s downward header from his cross had too much power for Romero.
And they were ahead five minutes later when Shelvey and Sigurdsson combined for Ayew to slip through Gomis.
The Frenchman’s finish lacked but it still squirmed its way past Romero at the keeper’s near post and victory was preserved by Williams’ terrific tackle at the death to deny Rooney.