Following a goalless initial encounter at Hillsborough, Tuesday's return was another cagey encounter and Swansea boss Carlos Carvalhal saw his Premier League side create little of note during the first half versus his former employers.
But Swansea's top scorer Ayew came on at the interval and poached his ninth of the season before Nathan Dyer quashed Wednesday's dwindling hopes 10 minutes from time.
A 4-1 thrashing at Brighton and Hove Albion on Saturday put Swansea back in the Premier League relegation zone and they were arguably second best in the first half at the Liberty Stadium.
Kristoffer Nordfeldt parried Jacob Butterfield's swerving shot from outside the area just before the half hour and the Swansea keeper reacted sharply to keep out Jordan Rhodes' diving header from Lucas Joao's cross.
Sam Clucas' improvised overhead kick was as close as Swansea came before the break and they were grateful for Nordfeldt's assured handling after the marauding Joao cut inside Kyle Bartley
9 - Swansea City are unbeaten in the previous nine competitive games in which Jordan Ayew has scored for them (W7 D2 L0). Charmed. pic.twitter.com/mPPHy1e23Q— OptaJoe (@OptaJoe) February 27, 2018
Carvalhal elected to send on Martin Olsson and Ayew in a double change that paid dividends when Tom Carroll's 55th-minute drive remarkably struck both posts, leaving the Ghana international to snaffle the rebound.
Dyer ensured a home tie against either Tottenham or Rochdale in round six when he sprung the Wednesday offside trap – a VAR referral fell in the winger's favour – to slide home Tammy Abraham's pass.