Niall McGinn’s long-range shot rattled the far post early on, after leaving goalkeeper Ben Williams motionless.
At the other end Anthony Wordsworth lashed a shot over and Bees goalkeeper Richard Lee denied Ian Henderson from close range on the half hour, after Karl Duguid had helped the ball on in the area.
But Brentford went ahead 11 minutes into the second half. Duguid was adjudged to have brought down Brentford left-back Jake Bidwell in the area and although Williams made a good save from Gary Alexander’s penalty, the U’s failed to clear and McGinn lashed a superb low shot into the net.
But Gillespie equalised with seven minutes left when he followed up to score from close range after Anthony Wordsworth’s fierce effort had rattled the bar.
And two minutes later he lashed in a shot from more than 25 yards which eluded Lee and sailed in to give Colchester victory.