Michael Flynn fired the visitors into the lead on the hour at the Don Valley Stadium on Saturday, but Adam Le Fondre looked to have snatched a point for Ronnie Moore’s men when he fired home an injury-time penalty following Steve Williams’ handball.
However, Bradford responded well and promptly regained the lead when Hanson headed home Simon Ramsden’s corner.
There was little goalmouth action in the first half, apart from one brief spell of Rotherham pressure that saw them go close on three occasions.
Tom Pope saw his header saved, Gavin Gunning’s follow-up was also blocked on the line and the defender’s second effort was headed away for another corner.
Bradford broke the deadlock when Flynn finished off a flowing move with a calm finish from Gareth Evans’ cross. Le Fondre then levelled late on, but there was more drama to come as Hanson snatched a late second for the Bantams.