Colchester took a third-minute lead through Tom Lapslie, who headed in his first-ever senior goal from close range after visiting goalkeeper Frank Fielding had failed to hold on to Elliott Hewitt’s cross.
It got even worse for the leaders 11 minutes later when Macauley Bonne marked his first Colchester start since 2013 with a superb header from Matt Briggs’ excellent cross.
City skipper Wade Elliott’s low shot struck a post, midway through the first half.
But Chris Porter made it 3-0 in the 26th minute when he latched on to Hewitt’s pass and planted a precise shot inside the near post.
City reduced the deficit five minutes after half-time when James Tavernier’s attempted cross from just inside the Colchester half flew over U’s goalkeeper Sam Walker, who denied Elliott soon after.
Aden Flint then nodded in Korey Smith’s cross just after the hour-mark to make it 3-2, but Colchester held on for a precious win.