Ayew, who had earlier seen his second-half penalty saved by David Raya, struck nine minutes from time at the Liberty Stadium with a ferocious volley from 16 yards.
Brentford had to play the final 25 minutes with 10 men after Rico Henry was shown a straight red card for a lunging tackle on Connor Roberts, although television replays suggested he did make some contact with the ball.
Brentford had finished the Championship season three places and 11 points above Swansea, but the two teams came into the contest on the back of differing emotions.
Swansea secured the final play-off spot in unlikely fashion by winning 4-1 at Reading and profiting from a six-goal swing at the expense of Nottingham Forest, whom they finished level on points.
Brentford's shock home defeat to lowly Barnsley cost them automatic promotion and boss Thomas Frank said his squad had felt the pain of that setback.
But Brentford had beaten Swansea 6-1 on aggregate in their two league meetings, and Frank insisted that would count in the Bees' favour on a psychological level.
But Swansea slowly settled and Brewster, who has scored 10 goals since his January loan move from Liverpool, produced a stinging shot which Raya pushed away.
Watkins planted a header wide at the other end, but it was Swansea who finished the half on top and came closest to opening the scoring.
Ayew met a Gallagher corner with a header which cannoned off a post and Brewster almost bundled home the rebound as Raya grasped the ball on his line.
Brentford had the final word of an absorbing first period when Benrahma beat two defenders but sent his shot over Mulder's bar.
The caution count was also rising – Swansea defenders Ben Cabango and Jake Bidwell and Brentford pair Jensen and Henrik Dalsgaard going into referee Keith Stroud's notebook – as the tension began to grow.
Fulton, making his 100th appearances for Swansea, fired straight at Raya before Ayew's quick feet opened up the goal for a shooting opportunity which he placed just wide.
Henry's red card tilted the tie Swansea's way and Ayew – after holding his head following his spot-kick miss – made sure the Welsh side took a narrow advantage to Griffin Park on Wednesday with a strike to remember.