The Lanarkshire side were held to a 1-1 draw at Cowdenbeath - both goals coming in stoppage time - to draw level with Dundee on points but they move ahead by virtue of the fact they have scored more goals.
Hamilton hit the woodwork three times - twice through Jason Scotland - as they looked the more menacing team at Central Park but it looked as if the game would finish without a goal.
Mickael Antoine-Curier, a second-half substitute, then looked to have won it for Hamilton when he struck in the first minute of injury-time.
However, Hamilton's celebrations were cut short when Tom O'Brien earned Cowdenbeath a point five minutes into added time.
Dundee attracted a crowd of almost 5000 to Dens Park but slipped up 1-0 at home to Falkirk, who cannot be counted out of the title race.
Peter MacDonald came close on a couple of occasions for Dundee early on - hitting the side-netting with a shot and then seeing a header cleared off the line by Mark Millar.
It was Falkirk who made the breakthrough after 19 minutes when Mark Beck headed past Kyle Letheren from a corner and the goal was to prove decisive.
Falkirk should have made life easier for themselves in the second half but, not for the first time this season, failed to convert a penalty kick.
This time, Millar saw his effort saved by Letheren but Falkirk held on for the victory.
Raith Rovers also picked up three points by slender means, edging Alloa Athletic 1-0 at Recreation Park.
Raith had the better of the first half action but could not turn their chances into goals.
Joe Cardle hit the crossbar early in the second half before Callum Booth curled a free-kick beyond Scott Bain after 50 minutes for the only goal of the game.
Dumbarton won 2-1 at Livingston with two late goals after Jason Talbot was sent off for a challenge on Paul McGinn with 10 minutes left.
Livingston looked untroubled at that stage as they led through a header from Nejc Mevlja after Keaghan Jacobs had supplied the cross.
It all turned sour after the red card. Craig Sives gave away a penalty which Chris Turner converted and Chris Kane was on hand to sweep a parried shot into the back of the net that keeps alive Dumbarton's hopes of reaching the play-offs.
Queen of the South pushed Morton closer to the edge with a 3-0 win at Palmerston Park.
Queens made a bright start and took their reward after nine minutes when Chris Higgins headed in from a corner by Chris Mitchell.
Gavin Reilly and Higgins both had chances before half-time but could not take them.
Derek Lyle finally scored Queens' second four minutes into the second half after a defensive mistake. Dougie Imrie almost pulled a goal back for Morton but his shot struck the crossbar.
Reilly made sure with a third for Queens with 10 minutes left.