Ulster will enjoy home advantage in their United Rugby Championship quarter-final after securing a top-four finish by beating the Sharks.
The hosts were cruising towards victory until the visitors scored two tries in the final four minutes to set-up a tense finale in Belfast.
The province led by 17 points thanks to tries from Michael Lowry, Stuart McCloskey and James Hume.
However replacement Grant Williams sparked a late Sharks rally.
Having produced a polished display for 75 minutes, Ulster nearly saw victory clutched from their grasp but held on and can now finish no lower than fourth.
They currently sit second, three points ahead of Munster and the Stormers - both of whom play their final regular season matches on Saturday.
The result will provide Ulster with a major boost as they backed up their crucial away win over Edinburgh at the end of April with another vital victory.
A season that was in danger of unravelling after three-straight URC defeats and a European exit at the hands of Toulouse remains alive as they seek a first trophy since 2006.
Improved Ulster rediscover home form
In years gone by Ulster have leaned heavily on consistency at home that has kept their season alive both domestically and in Europe while away fixtures have, perhaps predictably, been more of a mixed bag.
However recent back-to-back defeats at Kingspan Stadium dealt something of a hammer blow to the narrative of a home fortress, as Ulster ran out on Friday seeking their first win in Belfast in over two months.
The first half performance was a vast improvement on their last home outing against Munster, as they remained composed in attack and proved more than a match for the Sharks up front.
On a pitch that contained no less than five of the starting South Africa side from the 2019 World Cup final, including two back rows in Siya Kolisi and Duane Vermuelen, it was Ulster's Nick Timoney who shone brightest in a magnificent individual display.
The flanker poached a pair of first half penalties to snuff out the Sharks' two most dangerous attacks and carried effectively throughout in a varied attacking display from the hosts.
Billy Burns' twice dinked kicks over the top for Ethan McIlroy, who gathered on both occasions and went close to finding the opening try but was stopped short by a well-organised Sharks defence.
The Burns-McIlroy combination did eventually play a pivotal role in breaking the visitors' resistance as the fly-half's long pass found the wing who stepped inside before his deft offload sent Lowry over.
Chasing any form of win to secure a top-four finish, it was Ulster who came out of the traps faster after the break with McCloskey streaking clear on a perfect line before crashing through Aphelele Fassi for a rousing second try.
It all seemed to be going the way of the hosts, who went toe-to-toe with the Sharks physically, soaking up multiple phases of pressure before the visitors eventually battered down the door via replacement prop Ntuthuko Mchunu.
Despite finally having their defence breached there appeared to be no panic in the Ulster ranks, and they re-established their 17-point lead just two minutes later when Robert Baloucoune broke free on the right and fed John Cooney who sent in Hume.
The Belfast crowd rose to meet what was a thoroughly polished display from their hosts as the game appeared as good as done, with Cooney brilliantly hunting down replacement Williams allowing Matty Rea to exact another turnover.
However the Sharks, themselves chasing a home quarter-final, did not go quietly as Williams slalomed through the Ulster defence and found Marius Louw to finish on 76 minutes.
Even then, Ulster enjoyed a 10-point lead that appeared fairly comfortable, particularly with the ball deep in Sharks territory.
However one deft dink over the top saw Williams gather and scamper the length of the pitch as a thick air of tension suddenly descended upon Kingspan Stadium.
Time was on the hosts side, and one midfield turnover ended the contest and alleviated fears of a late collapse.
Ulster: Lowry, Baloucoune, Hume, McCloskey, McIlroy, Burns, Cooney; Warwick, Herring, O'Toole, O'Connor, Henderson (Capt.), Rea, Timoney, Vermeulen.
Replacements: Andrew, O'Sullivan, Milasinovich, Treadwell, Rea, Doak, Moore, Lyttle.
Sharks: Fassi; Kok, Am, Louw, Mapimpi; Bosch, Hendrikse; Nche, Mbonambi, du Toit (Capt); van Heerden, Hugo; Kolisi, Venter, Buthelezi.
Replacements: Vuuren, N Mchunu, K Mchunu, Andrews, Labuschagne, Notshe, Williams, Chamberlain.