Millwall 2 Rotherham 1
Just seconds after Michael Proctor's stoppage time penalty looked to have given Ronnie Moore's side a point, the Australian midfielder rose unchallenged to steer a header beyond the grasp of keeper Mike Pollitt.
It was tough on Rotherham, who had fought their way back into the match in the second half after Dennis Wise had inspired his side to dominate the first half.
Millwall were looking for their sixth win in nine games and posed the greater threat prior to the interval, with Paul Ifill and Danny Dichio forcing saves from Pollitt before Neil Harris put them in front on 38 minutes.
Dichio flicked a long ball into the area and Harris cut inside Shaun Barker and clipped a cool shot into the corner of the net.
Rotherham had their hosts on the back foot after the break, with Andy Monkhouse's shot deflected over on 47 minutes.
Chris Sedgwick was then unlucky to drag his shot wide from a tight angle after a superb mazy dribble had taken him away from three defenders into the area.
Sedgwick then blazed a shot over Willy Gueret's crossbar from 10 yards and Rotherham's luck appeared to be out.
However, they were awarded a penalty in injury time when Martin Butler was bundled over by Darren Ward, and Proctor blasted his kick straight down the middle to equalise.
The visitors, though, failed to hold on to their lifeline, and Cahill struck to boost Millwall's promotion prospects.