The visitors, who will travel to Vanarama National League side Solihull Moors in the next round, got the better of the Northern Irish Premiership outfit thanks to a goal three minutes from time for Serge Atakayi.
The Ibrox youngsters started brightly with Jamie Barjonas setting up Nathan Patterson whose drive across the face of goal was turned behind for a corner.
Ballymena came close on 17 minutes when Ryan Mayse cracked in a shot but the woodwork came to Rangers rescue.
The visitors had the next chance on 25 minutes. Docherty released Dapo Mebude but Jordan Williamson was equal to his low drive. Williamson blocked a Mebude header just after the restart with Mayse quickly trying his luck again but his shot just cleared the bar.
James Maxwell looked to have put Rangers ahead on the hour with a dipping effort but Williamson stuck up a hand to save.
As the pace quickened, Grezda headed just over and Rangers keeper Kieran Wright tipped a shot by Declan Carville past the post. A goal had to come and Jamie Barjonas seized on a mistake by Jonathan Addis to set Finn Atakayi up to drill home.