The home side had the better of the game but fell behind to Ryan Stevenson's header just after the hour mark.
But the Dons continued to press and were rewarded when Hamill slid a Johnny Hayes cross into his own net.
It means Aberdeen finish eighth in the table, ahead of what is sure to be a summer of change at the club, with nine players having already been told their future lie away from the club.
Hearts end the season two places and four points worse off although they still have the spectre of a possible points deduction hanging over them, which could consign them to League One, after Lithuanian parent company, UBIG, declared themselves insolvent.
The Jambos were fortunate not to fall behind early at Pittodrie as Josh Magennis' lifted shot was cleared by the backtracking Dylan McGowan before Cammy Smith headed a Joe Shaughnessy cross narrowly over.
The Hearts goal came under further pressure when Niall McGinn saw a 15-yard shot saved by Jamie McDonald, who was called into action again to tip a Magennis effort over the bar.
Despite having been under the cosh for much of the game, Hearts snatched the lead when David Smith's corner found the unmarked Stevenson and he headed beyond home keeper Jamie Langfield.
But with 13 minutes to go, Aberdeen claimed a deserved equaliser when Hayes turned in the penalty area and sent over a teasing ball that Hamill slid in to clear but succeeded only in turning the ball into his own net.
With the season drawing to a close, Hearts sent on Marius Zaliuskas for a final appearance before leaving the club in the summer, while Aberdeen's departing midfielder Gavin Rae was given a standing ovation when substituted in his final appearance for the club.