Ben Watson's second-half strike handed Crystal Palace victory and heaped more misery on basement side Colchester.
Phil Ifil gave Palace the lead when he scored his second own goal in a week, touching in Danny Butterfield's cross from six yards.
Kevin Lisbie equalised 90 seconds later when he converted Clive Platt's pass past keeper Julian Speroni.
But with just 15 minutes left, up popped Watson who prodded in a great right-wing cross from Ashley Robinson.
Crystal Palace boss Neil Warnock:
"I am going to crack open a bottle of champagne because now we are safe.
"When we were second from bottom, if you had told my chairman we'd be three points off the play-offs now, he'd have said you were in cloud-cuckoo land.
"So it is great for us, and I am sure the chairman will let me have a drink."
Colchester manager Geraint Williams felt a late Kevin Lisbie goal should have counted:
"James Scowcroft was three yards offside in the build-up to their goal and Lisbie was level with their last man when his goal was disallowed.
"You have to give Palace credit but it is disappointing when two major decisions go against you."
Crystal Palace: Speroni, Butterfield, Lawrence, Hill, Hills (Fonte 79), Moses (Scannell 84), Derry (Robinson 63), Watson, Soares, Scowcroft, Morrison.
Subs Not Used: Fletcher, Hughes.
Booked: Hill, Robinson.
Goals: Ifil 21 og, Watson 74.
Colchester: Gerken, Ifil, Coyne, Virgo, White, Duguid, Izzet (Elito 77), Hammond, Jackson, Platt (Vernon 87), Lisbie.
Subs Not Used: Bankole, Watson, Balogh.
Booked: White, Izzet, Lisbie.
Goals: Lisbie 23.
Ref: Phil Joslin (Nottinghamshire).