Both sides were reduced to 10 men in the quarter-final.
The tie was still deadlocked at 2-2 after extra-time but it was Queens who eventually came out on top following an epic night and they progress through to Wednesday's semi-final draw alongside Arbroath, Cowdenbeath and Partick Thistle.
The Dumfries side had taken the lead through Nicky Clark, before Barrie McKay levelled for Rangers and substitute Kevin Kyle saw red after just 13 minutes on the park.
Lee McCulloch netted from the penalty spot and Willie Gibson was also sent off, before Gavin Reilly forced the tie into extra-time with an injury-time equaliser.
The Palmerston outfit came out on top when Dean Shiels and Anestis Argyriou both failed to covert when the tie went to penalties and Ryan McGuffie claimed the decisive goal in the shoot-out.
Rangers made two changes from the side who drew with Annan in the Irn-Bru Third Division at the weekend.
David Templeton missed the third round tie after suffering ankle ligament damage on Saturday, while Sebastien Faure was dropped to the bench.
Argyriou returned from injury to claim a starting role and Francisco Sandaza was also drafted into the side for the visit of the Second Division leaders.
A minute's silence was observed before kick-off in memory of the 96 who perished at Hillsborough, as Rangers sent their support to the loved ones of those who lost their lives.
Like Liverpool, the Light Blues also endured tragedy with the loss of 66 supporters who died in the 1971 Ibrox Disaster.
Once the match was underway, Queens looked up for having a go and carved out the best two chances of the opening spell.
Neil Alexander was called into action to save well from a well-struck Chris Mitchell drive from the edge of the area.
The goalkeeper then had to react quickly again moments later, this time to tip just over the crossbar from Daniel Carmichael as the visitors continued to push for the opener.
Rangers had been poor but there was some hope for their fans just before the break when Shiels latched onto a lovely pass from Ian Black but his angled drive was blocked.
The half-time whistle was met by jeers from the home crowd and the second half was four minutes old when Queen of the South surged into the lead.
Gibson was the provider with a cross from the left which found Clark and he sent a powerful downward header past the grasp of Alexander and into the back of the net.
Only a superb save from the Rangers goalkeeper prevented Clark from grabbing his second of the night two minutes later with a shot at the near post.
Sandaza was replaced by Kyle before Rangers immediately hauled themselves level through McKay after 55 minutes.
The Queens defence failed to deal with a corner from Black well enough and the ball broke for the teenager to rifle home from six yards.
Kyle picked up a yellow card just five minutes after coming off the bench and he was then shown a red card by referee Stevie O'Reilly with 67 minutes on the clock for a challenge on McGuffie.
Despite being down to 10 men, Rangers took the lead after 71 minutes when the referee pointed to the penalty spot after McCulloch was fouled by Chris Higgins in the box.
The skipper brushed himself off to take the spot-kick and sent Robinson the wrong way to leave the net bulging.
Queens rattled the woodwork late on when Mark Durnan's header cracked off the post, before Gibson picked up a second yellow card with a couple of minutes of the regulation 90 remaining for a foul on Kal Naismith.
Just when Rangers thought they had held on for the win, Reilly netted deep into injury time and the goal was allowed to stand despite furious claims he was offside.
With the tie in extra-time, Rangers came close to scoring again when Lee Wallace's shot was blocked by the goalkeeper and Shiels rippled the side-netting with the rebound.
Alexander then blocked to prevent Queens the winner in the final minute of extra-time with Daniel Orsi through on goal, sending the game to penalties.