In a game of few clear-cut chances, a much-changed Hull side had taken the lead shortly after half-time, when Jon Toral combined well with Nouha Dicko and finished tidily.
But Ferguson levelled the scores with nine minutes to go when he took a short corner, got the ball back and curled a sumptuous finish into the top corner.
His second, three minutes later, was even better, a free-kick floated past George Long and into the net.
It was harsh on the Hull keeper who, for 80 minutes, had been superb to keep out the home side, but was no match for Ferguson’s magic.
For long periods this was not a game that looked like producing such drama or quality. Hull made eight changes, clearly prioritising the league where they have been in superb form recently, while Millwall looked sluggish.
After a soporific first half-hour, the game finally sparked into life with a flurry of chances.
Aiden O’Brien came closest to breaking the deadlock before the break, first firing wide from Tom Elliott’s flick-on, then seeing his header from point-blank range brilliantly clawed away by Long.
Seconds later it was the home keeper, Jordan Archer, who was called into action, getting down well to push away Todd Kane’s first-time shot, after good work down the left from David Milinkovic.
Barely two minutes later, Millwall spurned another glorious chance to go ahead as O’Brien left Jed Wallace’s cross to his strike partner Elliott, only for the big man to get the ball stuck in his feet five yards out, with the goal gaping, allowing Long to gather.
There would have been nothing the Hull keeper could have done about O’Brien’s next chance, as he deftly flicked another Wallace cross towards the near post, only to see it flash inches wide.
The Hull opener was against the run of play but came from the best move of the game.
Toral carried the ball through midfield unchallenged before feeding Dicko and continuing his run into the box. Dicko’s cross was perfectly weighted and Toral deftly touched it home.
In response Neil Harris made a triple substitution to try and spark his side into life, introducing Ferguson, who turned the game on its head.
With time running out the full-back produced a contender for goal of the season with his clever short corner routine and then, with a replay looming, delivered from a free-kick to earn the Lions a spot in the fourth round.