An early strike after just four minutes from Andy Little provided the Light Blues with the perfect start but the home side battled back and netted before the interval through striker Andy Jackson.
No further goals were scored in the second half but in the 109th minute Lee McCulloch's powerful header secured his side's place in Monday afternoon's second round draw.
The playing surface could not have been better for kick off and the travelling Bears were vociferous as the eleven Rangers players strolled out on to the pitch in the club's stunning new home kit.
The atmosphere was electric in the compact stadium and on four minutes the fans decked in red, white and blue were doing the bouncy when Ulsterman Little fired in the opening goal.
Lee McCulloch threaded a pass through the club's number 9 who showed blistering pace before calmly placing a left foot finish beyond Michael Andrews.
Brechin, however, responded well and should have been back on level terms with eight minutes on the clock when Jackson's cutback cross found midfielder Craig Molloy but his take effort was easily gathered by Neil Alexander.
Rangers continued in search of a second goal with Lee Wallace inches away with a 25 yard shot before full backs Lee Wallace and Kirk Broadfoot tested the City keeper with fine efforts.
Before the half hour mark ref George Salmond was called into action when Little was hauled down in the box and the official let play continue, a decision which frustrated the player and McCoist in the away dug out.
But on 43 minutes Brechin were back on level terms when Jackson latched on to a long ball and he made the most of hesitant defending before slotting the ball past Alexander at his near post.
At the start of the second half Rangers showed more urgency and after Molloy had volleyed high and wide on 47 minutes Ian Black had a curling free kick tipped around the post.
With the rain now pouring from the skies conditions were becoming tough for both sets of players but on 70 minutes good link up play by the industrious Wallace and McKay led to the full back playing a good cross which the tiring Black was unable to control.
Six minutes later and a good cut back from Little found Macleod but the youngster's left-foot effort was parried away by Andrews.
McKay then tried his luck with a clever flick from another Wallace cross but again Andrews was there to save the day and the game moved into extra time.
The keeper, however, could do nothing to stop the winner and McCulloch deserved to get the goal for his all-action display.
Macleod's corner kick was dangerous and Jig rose above Brechin's defence to power the ball off the slippery surface and into the roof of the net in front of the jubilant Bears who were magnificent throughout the 120 minutes.
Man of the Match - Lee Wallace: Full back was full of energy and a contstant threat down the left flank.
{gallery}/Matches/s1213/2012_07_29 - Brechin City{/gallery}















