Despite Palace's Aaron Bissaka having two shots on goal inside the opening two minutes, there were few real chances of note in the first half of this London derby.
The Eagles forward rifled an effort over the crossbar from the home side's first attack of the afternoon and then found himself played through on goal a minute later, only to be denied one-on-one by Brentford's Mark Smith.
After that, chances were few and far between, though both sides played good football. Neither could break the other down, with Palace standing firm after a lengthy period of Brentford possession. Despite the visitors' early dominance of the ball, they looked no more likely to snatch the lead than the Eagles - with Gary Issott's side looking threatening on the counter.
Just before the half hour mark, the Eagles' resilience finally paid off. Jacob Berkeley-Agyepong surged through the middle after regaining possession and played Aaron Bissaka through. The Palace striker made no mistake, slotting a low effort beyond Smith to open the scoring.
Bissaka's clinical finish was to separate the two sides at the break, with few other real chances falling for either Palace or Brentford.
It was the Eagles who started the second half stronger, with Ollie O'Dwyer's half-volley testing Brentford's Mark Smith five minutes after the restart. The goalkeeper did well to turn the towering defender's venomous effort round the post.
Palace enjoyed a succession of corners, which Brentford dealt with, until O'Dwyer meant an in-swinging set piece from Jason Lokilo and thumped a header past Smith, deservedly doubling the home side's advantage with 55 minutes on the clock.
Brentford pulled one back just over ten minutes later. O'Dwyer rose well to head a corner clear, but only as far as Montell Moore, who took a good first touch before lashing a powerful effort into the top corner from 25 yards.
Moore had two good chances with ten minutes to go, first firing a powerful volley at goal, which Perntreou parried wide, before curling a second shot narrowly wide of the far post.
Brentford continued to pile on the pressure, desperately searching for an equaliser, and their efforts were rewarded with seconds left of regulation time. The visitors won a free kick on the edge of the Palace box, which Sam Saunders curled into the bottom corner, leaving Perntreou with no chance. Several Brentford player had stood in and around the Palace wall, obscuring the goalkeeper's view, and the tactic paid off.
The game had one final twist , with Saunders again being the one to provide it. Brentford broke on Palace, with both sides pushing for a winner, and it felt to the midfielder on the edge of the area. He managed to move the ball on to his left foot before smashing a powerful strike beyond Perntreou, dramatically snatching the three points for the visitors.
Palace XI: Perntreou; Wynter, Croll, O'Dwyer (Sturgess, 67), Fryers; Lokilo (Forte, 76), Dymond, Hoare, Gray, Berkeley-Agyepong (Hall, 90); Bissaka.
Subs: Gregory, Breimyr.
Brentford XI: Smith, Laucys, Field, Macleod, Milenge, Laurent, Senior (Alves, 60), Holldack (Westbrooke, 82), Udumaga, Moore, Saunders.
Subs: Cole, Tzanev.