The Dons had started the better of the sides at Pittodrie but quickly fell away, and it was Killie who deserved the win with Irishman Conor Sammon causing the home defence problems.
Aberdeen made just one enforced change from the side that beat Alloa Athletic in the CIS Cup in midweek, with Peter Pawlett replacing cruciate injury victim Fraser Fyvie in the midfield.
With Sone Aluke still suffering from an Achilles injury, Darren Mackie maintained his place in the Dons starting line-up.
Kilmarnock also advanced in the League Cup, courtesy of a 6-2 win over Airdrie United, and they made three changes, with James Fowler, Hamill and captain Craig Bryson replacing Tim Clancy, Garry Hay and Liam Kelly.
Striker Harry Forrester, who has joined Killie on loan from Aston Villa, was handed a place on the bench for the visitors
The Dons went into the match leading the way in the SPL, and yet to concede a goal after their first two matches, while Kilmarnock were looking to improve on a record that had seen them go down to narrow defeats against Rangers and Motherwell.
Pittodrie had been bathed in sunshine just minutes before the match, but the players were greeted with a summer shower as they emerged from the dressing rooms.
The Dons started well and with two minutes gone, both Pawlett and former Cardiff man Magennis had drawn saves from Cameron Bell in the Killie goal.
A Paul Hartley free-kick after 15 minutes caused problems for the visitors, Mohamadou Sissoko heading over his own goal to clear the danger.
Two minutes later another Hartley free-kick was spilled by Bell, but the goalkeeper recovered well to block from Rory McArdle before the ball was scrambled away.
Killie were starting to look more lively, but were unable to test Dons keeper Mark Howard, who was a spectator as Sammon shot over on the half hour.
When Sammon finally registered a shot on target after 38 minutes, Howard struggled. The ball seemed to go right through the former Arsenal man but McArdle was able to clear.
A minute later, McArdle was again the Dons hero as he made a perfectly-timed challenge to deny Sammon another clear shot at goal.
As the half drew to a close, Magennis was allowed a shot at goal despite looking to be in an offside position, but hit over the bar.
The sides continued to cancel each other out after the interval.
Five minutes after half-time, Aberdeen's Mackie created space for himself with a fine turn, but his shot was deflected away for a corner.
The striker headed wide shortly afterwards, having ghosted in at the back post to meet another Hartley free-kick.
The Dons replaced Magennis and Maguire with Scott Vernon and youngster Mitchel Megginson just before the hour, but Killie were next to threaten.
Dayton's short corner allowed Hamill to cross, but Howard was quick to react and beat the ball away from the head of Sammon for another corner.
With 20 minutes remaining, Jerel Ifil's error allowed the dangerous Sammon in again, but Howard did well to palm the striker's low shot away.
Sammon and McArdle required treatment after a clash of heads seconds later, but both were able to continue.
Having returned to the pitch, McArdle attempted an ambitious bicycle kick in the Killie box, but he failed to find the target.
Killie's best move of the match ended with Hamill exchanging passes with Sammon before curling an excellent shot towards the top corner, Howard doing well to tip over.
From the resultant corner, Mackie had to be alert to head Sissoko's effort off the line, and seconds later Manuel Pascali shot inches over the bar.
Hamill got the decisive goal in injury time as Howard and Megginson left a long ball to each other, allowing the Killie right-back to nip between the pair and turn the ball into the net.