An epic third-round tie remained all-square at 2-2 after 90 minutes and 3-3 after extra-time with spot-kicks eventually separating the two sides, Hearts winning 4-2.
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.
The home side made one change following their defeat to Ross County at the weekend for the visit of the Scottish Championship outfit.
Gary Oliver was drafted into the side in place of the injured David Smith, as the Jambos attempted to return to winning ways after three straight losses.
Queens headed to Tynecastle aiming for another top-flight scalp having dumped St Mirren after extra-time in the last round but headed home disappointed on this occasion.
Hearts were first to threaten the opposition goal when Callum Paterson turned and squeezed a shot through a number of bodies in the congested box only for Calum Antell to smother.
At the other end, Chris Higgins threw himself in front of a free-kick into the goal-mouth and sent a looping header just over the crossbar.
The breakthrough came after 15 minutes and it was Hearts who surged into the lead.
McHattie picked up the loose ball on the edge of the area, bore down on goal, and unleashed a low drive into the far bottom corner.
Queens responded positively to the setback and were back on level terms just three minutes later.
An Iain Russell corner was met by McGuffie and his header was blocked by goalkeeper Jamie MacDonald but the same player reacted quickly to stab home the rebound from a couple of yards out.
The visitors should have been celebrating again when the ball broke for Derek Lyle, following some good build-up play, but he somehow managed to blaze over with the gaping net at his mercy.
Queens then passed up another great chance just before the break when Russell whipped a teasing ball from the left into the path of Paton and he rifled inches past the upright.
Instead, it was Hearts who were back in the driving seat five minutes after the restart.
Referee John McKendrick ruled that Jamie Walker was brought down in the box by Andy Dowie and Hamill kept his cool to convert from the penalty spot to restore the Jambos' lead.
Again, the advantage was short-lived, with Queens restoring parity on 61 minutes.
Lyle embarked on a great run down the left flank before squaring into the path of Paton and all that was required was a simple finish beyond the grasp of MacDonald.
Hearts tried to regain the lead again - and grab what could be the winner - when Jason Holt teed up the shot for Walker but his effort fizzed just past the post.
Ian McShane then stung the palms of MacDonald with both sides pushing for the decisive goal as the tie entered the final five minutes.
Neither side could find the back of the net again during the regulation 90 minutes but Hearts were ahead for the third time in this tie just two minutes into extra-time.
Walker's corner picked out Hamill and his strike from 20 yards was flicked beyond Antell by skipper Wilson.
But Queens refused to give up and Higgins lashed high into the net on 115 minutes, as penalties loomed.