After away losses against Munster, Leinster, Ospreys and Zebre, rock-bottom Sharks slumped to a fifth successive league defeat.
Connacht, though, made it four wins from five and consolidated a place among the competition's early-season movers and shakers.
Connacht led by five points at half-time following an early Sean O'Brien try that Hanrahan converted while Hanrahan also landed a penalty following Sharks number eight Sikhumbuzo Notshe's touchdown.
Sharks improved after the break, going ahead through wing Werner Kok's touchdown that Curwin Bosch converted, but Hanrahan had the final say and Connacht could celebrate a statement away win.
Connacht looked to capitalise on the Sharks' brittle confidence and they made a dream start by scoring from their first attack.
The forwards built an imposing platform, driving their opponents backwards from a close-range lineout before patient phase-play ended with O'Brien powering over and Hanrahan adding the extras.
Sharks were boosted by the return of double World Cup-winning Springboks centre Lukhanyo Am and he made his presence felt early on by running hard at Connacht's defence.
But the visitors coped impressively through strong defensive organisation, highlighted by the Sharks making six handling errors during the opening quarter.
They eventually got it right, though, cutting the deficit eight minutes before half-time when Notshe rounded off a spell of pressure to claim an equalising touchdown.
Bosch missed the straightforward conversion attempt and Sharks infringed virtually from the restart, allowing Hanrahan an easy penalty chance that he accepted.
Sharks continued to spill possession in promising positions and Connacht comfortably preserved their advantage, leading 10-5 at the interval.
The third quarter followed a similar pattern in stamina-sapping humidity, yet Connacht's cause was not helped when referee Craig Evans yellow-carded lock Oisin Dowling following a technical infringement.
The Sharks took just two minutes to capitalise as they worked a one-man overlap and Kok sprinted over for a try that Bosch converted, giving his team a two-point lead.
Connacht had to dig deep, given the Sharks' improvement, but they stuck to their task impressively and Hanrahan kicked them back in front 13 minutes from time.
Sharks had a chance to go ahead after 74 minutes but replacement Boeta Chamberlain could not find the target from an angled penalty attempt, which summed up Sharks' season so far.