Eighteen-year-old Riley had only been on the field for five minutes when Michael O’Connor’s looped header put him clear but the substitute coolly slipped the ball past Darren Randolph to seal a deserved win for the Blue Square North outfit.
A man-of-the-match display from Randolph had looked to have done enough to earn the Addicks a replay at The Valley until Riley’s 81st-minute heroics.
The home side dominated the opening 45 minutes and were only denied a half-time lead due to some misfortune in front of goal and a series of fine saves from Randolph.
Charlton had the first strike at goal after the break when Jonjo Shelvey fired straight at Curtis Aspden on 55 minutes.
But the second half came to life after the arrival of Riley, with the teenager making no mistake after O’Connor’s good work to send the home fans wild.