Rangers book place in Scottish Cup quarters
Gerrard's men have struggled to hit top form since returning from the winter break and made life difficult for themselves again in Lanarkshire.
Scott Arfield gave the visitors the lead on the rebound after his penalty was saved by Luke Southwood.
However, Hamilton levelled before the breakthrough Lewis Smith and had huge appeals for a penalty turned down when Connor Goldson handled inside his own area.
Rangers clicked into gear in the final quarter, though, as Joe Aribo's strike restored the lead before Alfredo Morelos's first goal of 2020 and a late Arfield strike secured victory.
"I was very disappointed in us defensively in the first half," Gerrard told Rangers TV. "I had to address that at half-time and rattle a few cages and get them switched on and focused and in the right place defensively.
"Once we did that, we played some nice stuff, created a lot of chances and scored some really impressive goals."
St Johnstone and Inverness were the only other sides to reach the last eight on Saturday afternoon with victories over Ayr and Livingston respectively.
Aberdeen's run without scoring a goal stretched to five games as the Dons were booed off after a 0-0 draw with Kilmarnock.
Another all Premiership tie will go to a replay as St Mirren and Motherwell drew 1-1.
Holders Celtic are in action on Sunday when they visit third-tier Clyde.