An epic tie remained all-square after 90 minutes and extra-time with spot-kicks eventually separating the two sides.
Jamie Hamill, Chris Mitchell and Michael Paton all failed to convert from the penalty spot, with Dale Carrick's strike sparking celebrations in the home camp.
Hearts also needed penalties to overcome Raith Rovers in the last round.
Kevin McHattie had fired the Jambos into the lead but his opener was cancelled out by Ryan McGuffie, with the scoreline level at half-time.
The Edinburgh side nudged in front again through a Hamill penalty only for Paton to haul Queens back in the match and force the third round tie into extra-time.
Danny Wilson then netted just two minutes later but, unbelievably, the visitors restored parity again thanks to Chris Higgins.
Scott Vernon's second-half hat-trick helped ensure Aberdeen did not suffer another embarrassing defeat against lower-league opposition as Falkirk were beaten 5-0.
Joe Shaugnessy had given the Reds a 22nd-minute lead while Cammy Smith added a second nine minutes before the break as Derek McInnes' team made a positive start to the third-round clash.
They sealed their place in the quarter-finals with Vernon's treble as a comprehensive success was wrapped up.
A David Goodwillie hat-trick helped Dundee United beat Partick Thistle 4-1 in their clash at Tannadice.
The on-loan striker from Blackburn impressed with three goals and he was joined on the scoresheet for United by Ryan Dow.
Christie Elliot scored Partick's goal.
James McFadden scored with a backheel to secure Motherwell's passage into the quarter-finals with a 2-1 win over 10-man Livingston.
Bob McHugh had opened the scoring on 15 minutes for Motherwell and Danny Denholn was on target late on for Livingston.