It took just nine minutes for the deadlock to be broken at Selhurst Park, with some questionable defending from a set-piece allowing Palace to bundle themselves in front.
Sunderland failed to deal with a corner swung into the heart of their six-yard box and the ball ended up in the back of the net in rather fortuitous circumstances after bobbling off Ondrej Celustka and on to Gabbidon - who knew little about a historic moment in his career.
Steven Fletcher made a timely return to the Black Cats set-up as he stepped off the bench at the interval and levelled matters on 64 minutes with a trademark header from a Jack Colback cross.
Palace were not to be denied, though, and went back in front on 79 minutes when record-signing Gayle blasted home from the penalty spot after being upended by John O'Shea - who saw red for a reckless challenge inside the box.
A first win back in the big time was wrapped up in spectacular style in stoppage-time when substitute O'Keefe rifled a 20-yard drive in off the underneath of the crossbar - to leave manager Ian Holloway dancing on the sidelines.
Holloway rotated his complete starting XI for the second time in a week, reverting back to the side that started in last weekend's 2-1 defeat at Stoke following a shake-up for the midweek Capital One Cup exit to Bristol City. That meant a home debut for Croydon-born Jason Puncheon, making his Selhurst Park bow after joining on a season-long loan from Southampton.
But it was fellow summer signing Jose Campana who created the early breakthrough for the hosts. The former Sevilla man whipped in a ninth-minute corner that just evaded the head of Marouane Chamakh at the near post, the ball then bounced off Sunderland's Celustka before an unknowing touch from Gabbidon steered it past Kieran Westwood.
Ji Dong-won should have levelled for the Black Cats 10 minutes later but he was in two minds whether to throw a head or a boot at Celustka's tempting cross, and in the end he did neither, missing the ball completely when free in front of Julian Speroni's goal.
Paolo Di Canio introduced Fletcher from the bench at half-time, with the ineffective Ji making way, as the Scotland international made his first appearance since suffering an ankle injury in March.
Palace were still getting plenty of joy out of running at the Sunderland defence and pushing them back towards their own goal as both Mile Jedinak and Gayle created chances in the opening 15 minutes of the second half.
But it was Sunderland who scored the next goal of the game, with the returning Fletcher levelling matters on 64 minutes as he expertly headed Colback's cross past Speroni.
A defensive error then proved to be the visitors' undoing 15 minutes later as O'Shea lost control of a loose ball and, as Gayle nipped in, the Black Cats' captain caught him and conceded a penalty with referee Lee Probert showing the former Manchester United man a red card.
Gayle, who was playing League Two football with Dagenham 12 months ago, coolly slotted home the resulting spot-kick to put Palace back in the driving seat.
Substitute Jonny Williams came close to adding a third for the hosts but his well-struck effort was pushed away by Westwood with six minutes remaining, with the Republic of Ireland goalkeeper again forced into action late on as he tipped Kagisho Dikhacoi's long-range piledriver behind for a corner.
But Westwood could do nothing about O'Keefe's injury-time effort as the Palace substitute curled a sweet shot into the back of the net to seal the win for the home side.