The visitors took the lead with a hotly-disputed penalty after 17 minutes, with Michael Spillane adjudged to have handled in the box.
But Bees keeper Ben Hamer stopped Grant McCann’s spot-kick but was ruled to have moved and the Posh midfielder made no mistake on the second attempt.
That setback inspired the Bees, who drew level on 39 minutes when Craig Woodman whipped home a free-kick from the right after Charlie MacDonald had been hauled down on the edge of the box.
Brentford took charge after the break and won it with a superb 58th-minute move, Woodman crossing to the far post where Sam Wood headed back for Gary Alexander to plant a diving header into the top corner.
The home side should have wrapped it up as they went on to create a string of chances, the best falling to Alexander, who volleyed Miles Weston’s far post cross wide of the upright.
Peterborough keeper Joe Lewis kept his side in the game with a point-blank stop from Alexander and palmed a Wood effort from 40 yards past the post.