Ian Madigan's last-gasp penalty left Edinburgh heartbroken as Ulster hit back to clinch a 22-19 win at Murrayfield and a place in the Guinness Pro14 final.

Richard Cockerill's team were the odds-on favourites to join Leinster in the Dublin final next Saturday and looked to be on course as they scored three times through Stuart McInally, Darcy Graham and Chris Dean.

But Dan McFarland's Belfast-based outfit refused to relent and responded with tries from Rob Lyttle, Rob Herring and John Andrew.

The last touchdown left Madigan with a tricky conversion out wide which he nailed to level the scores going into the final minute.

But a Mike Willemse fumble handed Madigan another kick at glory, which he took to fire Ulster into their first final in seven years.

Cockerill had insisted his side were the underdogs - but they were firmly in control for 40 minutes. 

Duhan Van Der Merwe had been urged by Cockerill pre-match to get himself involved more in the action after a series of lacklustre displays. 

The message was taken on board by the former South Africa schoolboy international, who charged at the visitors at every opportunity. 

It took a brave last-man tackle from John Cooney to prevent him scoring the opener after some quick hands from Hamish Watson and Blair Kinghorn released the 17 stone flyer down the touchline. 

But there was no-one there from Ulster to plug a big gap on the short side two minutes later as Edinburgh skipper McInally peeled off the back of a line-out ruck before flopping over for the opening points. 

Jaco Van Der Walt's conversion skewed wide before Ulster mounted three swift counter surges as they looked to hit back immediately. 

They were repelled on each occasion by a dark blue wall - a pattern that would be repeated more than once before the break. 

But the first half was just as much about Edinburgh 's dominance in defence - with McInally, Watson, Magnus Bradbury and even Graham producing big interventions - as it was about Ulster's inability to capitalise at the vital moment in attack. 

The second half got off to another sloppy start for the Belfast outfit as Billy Burns' up-and-under sliced off the outside of his boot to put his side under pressure again. 

And Edinburgh took advantage to score again after 47 minutes. The forwards did the grunt work before Chris Dean fed Van Der Walt, with the stand-off shrugging away Burns' tackle to put in Graham to the score. 

Van Der Walt added the extras but the deficit was cut back to five within seven minutes as the hosts' resistance was finally broken when Lyttle danced in off his line to dot down under the posts for a try converted by Burns. 

By this point, the game was resembling a basketball match. 

Dean crossed over after Watson had bulldozed into the red zone - but this was the last time Edinburgh would have any control over matters. 

Again Ulster hit back just past the hour mark, with hooker Herring barging over from close range. 

With their lead cut to seven, Edinburgh were now wobbling. A defence that had been rock solid before the break was creaking and McFarland's men took advantage as Andrew squeezed over from a mighty line-out drive. 

Madigan had it all to do with the conversion out wide but slotted over to square things up. 

But with extra-time looming, Edinburgh substitute prop Willemse knocked-on to hand Madigan his shot at glory.