The Boxing Day clash at Villa Park appeared set to finish goalless until Gayle collected a pass from fellow substitute Jonathan Williams and curled the ball home from 20 yards.
The result moved Palace to 17th in the Premier League, above Fulham on goal difference, and left Villa just three points clear of danger following a fourth successive defeat.
Villa have now won just one of their last 13 matches on Boxing Day and have failed to score in eight of their last 11 outings.
Paul Lambert was without Christian Benteke and Ashley Westwood due to injury and suspension respectively, but Gabby Agbonlahor returned after completing a one-match ban. Palace's top scorer Marouane Chamakh missed out after picking up his fifth yellow card of the season last time out.
The home side dominated possession in the opening 25 minutes, but their final ball let them down, with Marc Albrighton particularly wasteful.
Palace improved as the half progressed, largely thanks to Yannick Bolasie. The 24-year-old winger collected possession on the left, skipped past Matthew Lowton and fed Cameron Jerome, who over-hit a throughball to Barry Bannan when he really should have shot.
Bolasie got the better of Lowton once again and advanced into the box, only for Nathan Baker to get back and force the ball out for a corner.
Libor Kozak saw his header superbly nodded over his own crossbar by Adrian Mariappa on the stroke of half-time as Villa came close to opening the scoring.
After a limp first 45 minutes, the second half exploded into life, with an off-balance Baker doing well to deny Bolasie a clear sight of goal.
Fabian Delph's vision and immaculate execution of pass then presented Andreas Weimann with a chance, but the Austria international's half-volley went straight into the arms of Julian Speroni.
Bannan, against his former club, almost put Palace in front on 54 minutes, but Brad Guzan did superbly to tip the ball on to the post.
Agbonlahor raced into the area but hit his shot straight at Speroni and, following a delightful move, Albrighton's clever cut-back set up Weimann, who fired over from inside the box.
Bolasie tricked his way past two opponents on 65 minutes and crossed for Jason Puncheon, whose fierce shot from 10 yards was saved by Guzan.
A scrappy finish looked destined for a draw until Gayle grabbed his third Premier League goal, and all three points for Tony Pulis side.
Palace have now won three of seven games under the former Stoke City boss, but face a daunting trip to Manchester City on Saturday.
Thank you for reading 5 articles this month* Join now for unlimited access
Enjoy your first month for just £1 / $1 / €1
*Read 5 free articles per month without a subscription
Join now for unlimited access
Try first month for just £1 / $1 / €1