A double substitution by manager John McGlynn paid off as Hearts scored a late winner against Scottish Premier League strugglers Dundee.
Hearts had twice hit the crossbar through a Michael Ngoo header and a Jason Holt thunderbolt as they gave Dundee keeper Rab Douglas a busy night.
It had looked like the Dark Blues would leave Tynecastle with a draw.
But, in 86 minutes, sub winger Arvydas Novikovas crossed to the back post where John Sutton dived to head home.
Both sides made two changes from their weekend fixtures.
Hearts brought back Ryan Stevenson after missing their League Cup semi-final success through suspension and 18-year-old Billy King made his debut.
Gary Harkins started for Dundee after rejoining the club from Kilmarnock and Nicky Riley was back in after missing the last two matches with a calf injury.
Hearts started the better and King came close to making a sensational start to his first-team career when he picked up the ball on the right before cutting in and firing a low left-foot shot just wide of goal.
Hearts were on top and Michael Ngoo, who scored on his debut on Saturday, almost notched his second for the club.
The on-loan Liverpool striker combined with Jamie Walker, Ngoo had his effort blocked and the rebound fell to Walker who had his shot saved by Douglas.
It was one-way traffic towards the Dundee goal, with King and Ngoo the main threat for the home side.
Douglas defied his years with a stunning save to deny Hearts when he dived low to his left to tip away a Walker shot from 25 yards that had taken a wicked deflection off the shin of Dee defender Lewis Toshney.
With half-time looming, Ngoo again came close to finding the net.
King crossed the ball in from the right, Ngoo won the header but the ball hit the back of Gallagher's head before clipping the crossbar and going over.
While Dundee were defending well, it wasn't until the 41st minute that they had their first effort at the Hearts goal.
John Baird crossed from the left and Riley shot high over the crossbar from the angle inside the 18-yard box.
With the wind at their backs more was expected from Dundee in the second period but it was the home side who kept piling on the pressure.
The crossbar came to Dundee's rescue for a second time when Holt's powerful shot from 25 yards had Douglas beaten.
The Hearts fans among the 11,284 inside Tynecastle were urging their side forward with chance after chance being created.
With a swirling wind and driving rain to contend with players from both sides were finding it difficult to control the ball.
On a rare foray upfront for Dundee, Colin Nish almost connected with a through ball from John Baird, Marius Zaliukas intercepting in the nick of time.
Dundee boss Barry Smith was the first manager to make a change, former Hibs midfielder Kevin McBride replacing Nicky Riley after 75 minutes.
Hearts boss John McGlynn then made his two changes as he searched for an opener. Novikovas replaced Billy King on the wing and Sutton came on for Holt.
The Lithuanian swung in a cross to the back post and Sutton's diving header gave the home side a deserved lead.
Novikovas slid the ball narrowly past the post from a Ngoo pass with a minute remaining and Douglas saved well from Walker as Hearts deservedly collected their first win of the season against the Dens Park club.