It was the third time in 10 months that he had walked away with the matchball in a game where Darren Ferguson's men appeared intent on throwing away the points.
Mackail-Smith broke the deadlock from the edge of the box after beating the offside trap in the 16th minute before strike partner Aaron Mclean doubled Posh's cushion nine minutes later despite a couple of bad touches before firing home. But dire defending allowed Steve Elliott to halve the arrears on the half-hour before Posh lost front man Mclean with a suspected dislocated elbow.
Mackail-Smith earned and converted a 51st-minute penalty that put Posh back in control but a terrible Shane Blackett own goal three minutes later allowed Rovers another lifeline.
Mackail-Smith completed his treble with an outstanding individual effort after 65 minutes, but predictably the visitors hit back on 74 minutes when Jeff Hughes, who had struck a post moments earlier, turned the ball into an empty net after a Chris Lines cross evaded the Posh defence.
Scott Rendell looked to have settled the contest eight minutes from time, heading home Chris Whelpdale's cross but Rovers striker Rickie Lambert set up a grandstand finish with a fabulous 84th-minute free-kick as the hosts held on for a 5-4 win.