Barnes struck after just eight minutes and Tom Heaton kept Palace at bay before substitute Gray hit a late second to ensure the Clarets finally registered their first success on the road this season.
It was also Burnley's first ever Premier League victory in London - at the 16th attempt - which lifted them above Palace and, crucially, eight points clear of the drop zone.
London football! Relive the action with Standard Sport's blog...
Can't see the live blog? Click here for the desktop site.
Palace XI: Hennessey, Ward, Kelly, Delaney, Van Aanholt, McArthur, Milivojevic, Puncheon, Zaha, Benteke, Townsend
Subs: Speroni, Flamini, Remy, Campbell, Lee, Sako, Schlupp
Burnley XI: Heaton, Lowton, Keane, Tarkowski, Ward, Boyd, Westwood, Hendrick, Arfield, Vokes, Barnes
Subs: Flanagan, Gray, Brady, Defour, Gudmundsson, Long, Pope
Referee: Robert Madley
WHAT THEY SAID
Sam Allardyce: "We've certainly got to get two more wins at the very least. And we still have some tough games, all of them are tough. So depending on the lads determination and drive now, and desire, the form that they are in, for me it's about trying to make sure they can continue to play at this level.
"Which for them would be very difficult because it's been a huge, huge effort physically and mentally. And somewhere along the line there may be a dip off. And if there is, be professional and good enough to win the game if its not quite the performance we have been giving. And that's the art of a good team."
Sean Dyche: "Points on the board - I've said it all season, it's all I'm interested in. That's all I'll be judged on, that's all the club will be judged on, that's all the players will be judged on.
"It's not because I sweep things under the carpet, I mean it 100 per cent. Points on the board this season is what it's about and can you get enough in the Premier League?"