Ian Madigan's last-minute penalty condemned Edinburgh to defeat in their final game at Murrayfield as Ulster claimed a thrilling first win in the Pro14 Rainbow Cup.
The hosts lost an early 12-0 lead - and had Hamish Watson and WP Nel sin-binned - as Ulster ran in five tries to rack up 31 unanswered points.
But yellow cards for the visitors' Michael Lowry and Nick Timoney after the break prompted an Edinburgh fightback to level late on before Madigan broke their hearts.
Victory lifts Ulster three places from bottom to ninth after their final fixture, while Edinburgh are 11th with a trip to Scarlets to come.
Both sides were already out of contention for a place the final, but served up a compelling contest with the pressure off.
Ulster had been dogged by Covid-19 issues, with 13 players self-isolating, while their options were further limited by injuries to seven others.
Edinburgh had one player unavailable after testing positive, but welcomed back Scotland internationals Watson, Jamie Ritchie, Ben Toolis and Duhan van der Merwe.
And in their final outing at the national stadium before the move to their new 8,000-capacity home next season, the hosts made a flying start as Van der Merwe, getting some vital game-time before joining the British and Irish Lions squad, crossed at the corner.
Blair Kinghorn sent the conversion wide but made no mistake after touching down following a terrific line break from James Johnstone.
Ulster responded quickly as James Hume powered over out wide to reduce the arrears, with Madigan converting.
Edinburgh had Watson sin-binned and were down to 13 men when Nel was yellow carded as Iain Henderson crossed for Ulster from a rolling maul.
The visitors capitalised on their numerical advantage as a great charge from Hume allowed Stuart McCloskey to race clear to score.
Adam McBurney - who will leave the province to join Edinburgh next season - completed a line-out drive, with Madigan hitting the post to miss out on a fourth successful conversion.
The second half would struggle to match the excitement of the first, but Rob Lyttle squeezed in at the corner to extend Ulster's lead.
Van der Merwe was replaced after appearing to taking a knock, with Cammy Hutchison coming on to make his Edinburgh debut.
The visitors lost Lowry and Timoney to the sin-bin in quick succession and Edinburgh profited as Pierre Schoeman barrelled over to spark the comeback.
Hutchison and Eroni Sau then added tries to level the scores, but Kinghorn's kick for the latter drifted wide and Madigan delivered a dramatic winning penalty from near the right touchline.
Edinburgh: Paterson; Sau, Johnstone, Taylor, Van der Merwe; Kinghorn, Shiel; Venter, Harrison, Nel, Sykes, Toolis; Ritchie, Watson, Muncaster.
Replacements: Willemse, Schoeman, Berghan, Kunavula, Morris, Pyrgos, Chamberlain, Hutchinson.
Ulster: Lyttle; Faddes, Hume, McCloskey, Gilroy; Madigan, Shanahan; McCall, McBurney, Moore, A O'Connor, Henderson; Matty Rea, Marcus Rea, Timoney.
Replacements: Herring, Warwick, O'Toole, Treadwell, Jones, Mathewson, Burns, Lowry.