Earlier Gary Kelly fired the visitors in front after 33 minutes with a quickly taken free-kick which caught Palace keeper Cedric Berthelin stranded at the opposite post, but Julian Gray levelled within two minutes with a superb 20-yard left-foot volley which whistled past a pack of players before settling into the right hand corner.
Then came Gallagher's clanger but anyway the Eagles plugged away and were the better side for long spells.
But 17 minutes from the end Kewell completed an excellent weeks work by holding off the challenges of Hayden Mullins and Danny Butterfield before neatly placing a left-foot shot past Berthelin.
Palace boss Trevor Francis said: "Today the players gave me more than I could of asked for with their performance - commitment and some great passing skills. It was a performance that we should not of gone out of the cup with.
"Despite the fact you can dominate the game when you are up against a Premiership side, they have a few players like Kewell that can put away a goal like that."
A satisfied Terry Venables said: "To get to the quarter finals is something, our boys played really well, we got a lucky break with the disallowed goal and everybody pitched in.
"We laid out our stall and everybody contributed to the game, nobody expected us to get this far so it's given us a real lift."