Munster comfortably dispatched Castres but fell short of a bonus point in a scrappy Champions Cup Pool 2 encounter in Thomond Park.
Second-half tries from Rory Scannell, CJ Stander and man-of-the-match Hanrahan moved Johan Van Graan's side back to the top of the pool, although with a degree of niggle in this game, next Saturday evening's return fixture in Castres is sure to be a feisty affair.
Two penalties from Hanrahan - a late inclusion at fly-half for the injured Joey Carbery - gave Munster a 6-0 half-time lead and the hosts were frustrated not to be further in front but Castres' well-organised defence and a tricky wind limited their try-scoring opportunities.
The 21,861-strong crowd watched Rory Scannell end the wait for a try in the 42nd minute, and Hanrahan's third penalty was followed by well-crafted seven-pointers from Stander (67) and the Currow-born number 10 with six minutes remaining.
With Andrew Conway seeing yellow, replacement Martin Laveau's last-minute try gave Castres something to take into next week.
A tight hamstring prevented Carbery from starting alongside Conor Murray for the first time in Munster red, with Chris Farrell also pulling out in the warm-up.
Hanrahan and Sam Arnold took their places, the former opening the scoring with a sixth-minute penalty after a strong carry by Stander off a scrum.
A try eluded Munster in a first quarter which saw them on the front foot with Tadhg Beirne and Chris Cloete both prominent. A mistimed lineout let Castres off the hook and allowed them to clear, while Munster were unable to profit from a midfield break by Andrew Conway.
Hanrahan's right boot doubled their tally in the 20th minute.
Munster, whose share of possession touched 80 per cent, were guilty of forcing it too much at times.
Castres centre Thomas Combezou did well to shut down a potential overlap, and the visitors managed to pinch another lineout with kicks from Hanrahan and Rory Scannell also going too long in the windy conditions.
The try deadlock was broken two minutes into the second half, Murray threatening off a ruck and getting his pass away for centre Rory Scannell to slip out of a tackle from Loic Jacquet and touch down to the right of the posts.
Hanrahan drew the conversion over for a 13-0 lead, his opposite number Benjamin Urdapilleta missing a penalty in response.
Castres emerged scoreless from a five-metre scrum, a crucial turnover from Peter O'Mahony launching Munster back towards halfway and Hanrahan's subsequent penalty extending the lead to 16 points.
Murray's final act was a slick break from a ruck and offload, setting up Stander to evade two tacklers and regain his feet to score his seven-pointer close to the posts.
They gained further momentum with Sam Arnold's offload out of a tackle that allowed Scannell and Alby Mathewson to flood through and send the supporting Hanrahan over for a deserved try.
However, the bonus point hunt never materialised as Castres dominated the closing six minutes - aided by Conway's yellow for an early tackle on Rory Kockott - and Laveau was freed up to score near the right corner.