Heart Of Midlothian 3 Dundee United 2
It took a soft foul and a deflected free-kick to seal it for Hearts, but they were hardly complaining after their first win in six games set them up nicely for a busy schedule of league and cup matches.
Although luck was on his side, top scorer Paul Hartley deserved his winning goal, following another fine midfield dis[play - while new signing Lee Miller enjoyed a dream debut by scoring Hearts' second goal.
United meanwhile, produced two world class free-kicks and had Stevie Crawford making his first appearance for the club, but they still have to win away from home in the SPL and remain stuck in the relegation zone.
The result might have been different had they taken a glorious early chance when Crawford, who was booed all afternoon for shunning Hearts in favour of United, fired in a left-foot shot which was parried by Craig Gordon.
The Scotland keeper could do nothing to stop United going ahead in the 20th minute as a trip on skipper Derek McInnes set up a free-kick 23 yards out which Barry Robson curled into the top corner of the net with a sweep left-foot strike.
Hearts stepped up the pressure and had more possession but their final ball was poor, and a Hartley free-kick, straight at the wall, provided further frustration. McKenna also shot wide when well placed, and while United looked comfortable in defence, their sporadic counter attacks brought half chances for Jim McIntyre and Crawford and a stinging Robson volley which Gordon somehow stopped one handed.
Despite lacking inspiration, Hearts equalised shortly before half time as Phil Stamp's corner was hammered home at the back post by skipper Steven Pressley.
Miller' s arrival at the start of the second period immediately gave Hearts an energetic new option up front, and within four minutes he had marked his debut with a goal as Hartley 's free-kick was knocked down by Kevin McKenna, and MIller reacted quickest, to score from point blank range.
United responded in swift and stunning fashion with a high challenge from Robbie Neilson giving the visitors a free-kick which was rolled into the path of full-back Alan Archibald, who lashed in an unstoppable left-foot drive.
WIth four minutes left, Hartley's deflected free-kick from outside the box gave Hearts the edge in a match where all five goals came from set pieces.
Hearts' boss John Robertson praised keeper Craig Gordon, saying: "Craig made a wonderful save from Barry Robson at 1-0 for United and that turned the game for us because it had been a poor first half and it took us 40 minutes to get going.
"We got a wee break at the end - it was a soft foul, but Paul Hartley made the most of it. We're delighted to get the win and that's a big three points for us."
New signing Lee Miller, who scored on his debut ,said: 'The manager told me to go on and ruffle them up, but I didn't expect to score so early. I just hope I can go on from this and stay in the team."
Dundee United's Barry Robson said: 'We've got good players and we're passing the ball well, but something seems to be going against us at the moment. There have been so many games this season that we have not deserved to lose. It's pretty hard to take when you lose a goal like that near the end.
"But we came down here and held our own and I thought we deserved to win the match. It was the same against Rangers last week, so I am sure we can turn things around."