Leon McKenzie fired a late double to send Peterborough into the southern section quarter-finals of the LDV Vans Trophy.
McKenzie, being chased by a number of first division clubs, took his personal tally to six goals in the last four games when seeing off second division rivals Brentford.
Flying winger Adam Newton, who was thrown as a 72nd minute sub created both of McKenzie's efforts.
Loan striker Richard Logan nodded Posh ahead on 22 minutes after a cross from Calum Willock had been deflected into his path, but defender Michael Dobson headed Brentford level eight minutes before the break.
Willock crashed a shot against the crossbar and Bees keeper Paul Smith pulled off a fine reflex save to keep out Curtis Woodhouse's bullet header as the match looked set to go all the way to extra-time.
But Newton's arrival soon changed that. He had only been on the field for nine minutes when he produced a pin-point cross from the right that McKenzie powerfully headed past Smith.
And then in the 89th minute Newton again tricked his way down the right and, after his shot had been saved by Smith's legs, McKenzie was on hand to lash the ball into the roof of the net.
Brentford hit a consolation with the final kick of the game when Stephen Hunt beat Mark Tyler from the penalty spot after a foul by Christopher Kanu.