Ally McCoist's side got off to an excellent start at Ibrox when Lewis Macleod put them in front in the 14th minute.
The Gers midfielder latched on to a Lee Walllace cross and rifled a powerful low drive below rival goalkeeper Mark Oxley.
However, the home team failed to pressurise the visitors after that and the capital club gradually edged their way back into the match.
Alan Stubbs' side dominated large swathes of the game and deserved to draw level in the 59th minute when Danny Handling turned in a David Gray cross.
Handling was ordered off shortly after that when he received a straight red card for a challenge on Rangers substitute David Templeton.
Rangers had what looked to be a strong penalty claim waved away early in the first period of extra time. Wallace appeared to be fouled by Gray in the Hibs penalty area, but referee John Beaton was unimpressed.
Law gave his side the advantage again in the first period of extra time when he collected the ball from Wallace and curled a shot beyond Oxley.
McCoist praised comeback kid Macleod after the midfielder ended seven months out of the game. The 20-year-old playmaker disappeared from the first-team scene at Ibrox last January after a viral issue caused complications with the muscles around his heart.
And the manager said: ""I was really encouraged by Lewis. It was a big concern for the lad when he was out but he's enjoying himself and he is like a new player for us.
"He's learning all the time and there's still improvement to come but we are thrilled with him. We want him to get goals for us and he did that tonight."
McCoist's men will meet Clyde in the next round ... and welcome back former captain Barry Ferguson to Ibrox.