Substitute O'Connor thumped home a 25-yard effort from an Isiah Rankin knock-down in the 84th minute and set the party celebrations in swing at Griffin Park.
Boss Allen had been hoping for a memorable 35th birthday, but thought time was running out after a tight game with few chances.
Defensive Wrexham had held the Bees at bay for most of the match and looked set to take a hard earned point.
In fact, the best chance to break the deadlock fell to Wrexham striker Hector Sam, who somehow fired wide when clean through after 71 minutes.
Brentford had plenty of possesion but couldn't turn it into chances as they struggled to find the final pass.
But just when it seemed all over, O'Connor sealed victory for the Bees with his stunning strike.
Livewire Jay Tabb, again one of Brentford's most influential players, then saved the points by heading off his own line in the dying moments.
The result means Brentford have won their opening two home games of the season and continues the feel-good factor at Griffin Park after the way Allen and his team avoided relegation last season.
For Wrexham it was a disappointing return after winning their previous two games of the new campaign.