Manager Gary Johnson made a shock departure on Monday night before double-promotion-winning former boss Darren Ferguson was lined up for a dramatic return.
Ferguson held talks with chairman Darragh MacAnthony earlier in the day and watched this last-gasp success from the directors' box.
Youth-team coach David Oldfield took charge as they climbed back into the League One play-off places thanks to on-loan Obika's late show as he turned in his first goal for the club after George Boyd had drilled the ball across the box.
Posh had gone ahead through Grant McCann's fourth-minute penalty after Boyd had been sent tumbling by Brentford defender Pim Balkestein.
Posh, who lost defender Gaby Zakuani to a dislocated shoulder, had strong penalty appeals turned down midway through the second half when a Tommy Rowe cross appeared to strike the arm of defender Michael Spillane.
But Brentford grew in stature as the game progressed and levelled 16 minutes from time after a bout of penalty area pinball. Posh goalkeeper Joe Lewis pulled off superb saves to keep out Marcus Bean and Gary Alexander but he was powerless to prevent Marc Laird from slotting home a rebound seconds later after a Myles Weston effort had struck a post. But Posh had the last laugh when Tottenham youngster Obika pounced from eight yards in stoppage time.