Stanley were wasteful thoughout in the first half. Bobby Grant rifled a shot wide in the first minute while his effort from six yards out minutes later took a deflection.
Striker Michael Symes also had a close-range shot saved by Gills goalkeeper Alan Julian while Sean McConville blasted inches wide.
They failed to take their chances, though, and were almost made to pay immediately after the break but Reds keeper Dean Bouzanis pulled off a point-blank save to keep out Mark Bentley's effort - the League One side's first strike on target.
The game was on a knife-edge but Accrington again forced the pace with Symes forcing a good save out of Julian and then Stanley substitute Billy Kee rifled over an open goal after the keeper had dropped a looping cross.
But Stanley got the goal they deserved when Kee knocked the ball down and Miles scored his solo effort to boost the Crown Ground club's finances by around £100,000 after they were almost wound up by the tax man in November.