• No go: Chris Henry is halted by Butch James
While Bath resign themselves to non-qualification for the second season in a row, the Ulstermen can now look forward to an epic encounter with Pool 4 leaders Biarritz on 15 January.
The match turned on a yellow card which was shown just after half-time to Springbok fly-half Butch James. It allowed Ulster, trailing by a point at half-time, to grab the initiative with Nevin's 56th-minute try. Man-of-the-match Humphreys slotted the touchline conversion and held Bath at bay while the home side could muster only a long-range try from Matt Banahan.
Ulster were caught cold in the first minute when Jack Cuthbert hit up through the middle and Lee Mears was on hand to send Matt Carraro in at the corner for an unconverted try.
Barkley soon added a penalty but Ulster hit back with a 10th-minute Adam D'Arcy try after the visitors tapped and a ran a free-kick and Diack provided his full-back with the scoring pass.
Humphreys converted but then needed treatment after a late 'hit' by James which escaped the officials' attention. Ulster prop BJ Botha was not so fortunate after a high tackle on Claassens and Barkley's second penalty made it 11-7 to Bath.
Humphreys and Barkley swapped further penalties but the Ulster fly-half seemed to be struggling with an injury and his tactical kicking was too often handing the initiative back to Bath.
As half-time approached, Ruan Pienaar broke dangerously with Humphreys and Trimble in support. Bath's defence snuffed out the threat but only at the cost of a penalty which was landed by Humphreys to again cut the lead to a point.
James' notoriously short fuse lasted just four minutes into the second half when he was sin-binned after a scuffle with Dan Touhy.
But, having worked their way into the Bath 22, Ulster gave away two penalties in quick succession.
As James waited for a break in play to return to the field, Ulster seized their chance to string together phase after phase and finally Paddy Wallace put centre partner Spence in at the corner. Humphreys converted magnificently and then added a 50-metre penalty for good measure to put his team ahead for the first time at 14-23.
Two penalties in quick succession saw Spence sent to the sin bin and Barkley pulled back three points from under the posts.
Suddenly Bath burst into life, attacking from their own 22 through Nick Abendanon and finishing off in spectacular fashion through Banahan in the opposite corner. Barkley failed to convert but Humphreys, immediately handed a penalty chance from 40 metres, stretched the Ulster lead to a decisive four points.