Manager Derek McInnes made three changes to the side that lost against Celtic on Sunday. Lewis Ferguson returned from suspension whilst Craig Bryson made his fifth start of the season and Ryan Hedges also made the starting XI - he has been carrying a slight knock in recent weeks. Michael Devlin, Connor McLennan and Jon Gallagher all dropped to the bench.
So Aberdeen lined up with a back four of Logan, McKenna, Considine and Leigh. Vyner and Ferguson were the sitting midfielders with McGinn, Bryson and Hedges in front of them and Cosgrove was up top.
Hamilton Accies also made three changes to the side that lost 3-2 at St Johnstone on Saturday.
Then in the fifth minute Accies won a free kick midway inside the Aberdeen half. In a clever move the ball was played deep to Scott McMann who was able to head the ball back into the path of the on rushing Mickel Miller and his first-time effort just went wide of the post. A warning for the Dons.
Two minutes later McGinn released Hedges down the right, the winger showed good pace and his cross was met by Cosgrove, but Ronan Hughes did well to challenge the striker. Logan then put over a deeper cross which again Cosgrove met but he could not get any power or direction in his header.
Aberdeen should have taken the lead in the 10th minute. Hedges played a delightful ball forward for McGinn who had space down the left, his early ball picked out Cosgrove, but the big striker's control let him down just as he looked as if he would fire home.
Then at the other end Accies had a great chance when Miller's shot was saved by Lewis but Ross Cunningham following up was only inches away from getting on the end of the rebound.
In the 15th minute Aberdeen took the lead after Lewis Ferguson won Aberdeen a free kick 25 yards out. The visitors themselves worked a clever free kick when Hedges rolled it short into the path of Ferguson. The midfielder showed tremendous strength to roll away from his marker and then with his left foot fired an unstoppable shot high into the roof of the net. A great free kick routine.
On 20 minutes Aberdeen won the first corner of the game. The ball broke off Cosgrove and very nearly fell into the path of Leigh. The left back then turned defence into attack with some excellent play, but the promising break broke down when Bryson's dummy failed to find a gold jersey.
On 25 minutes a cross landed at the feet of a well-positioned Logan but his shot was off target. Shay has not scored in 53 games and his effort did lack confidence. The ball then came out to Hedges at the edge of the area and his shot was deflected just over. The home side were struggling to contain the number of crosses coming into the box.
Two minutes later Accies won their first corner but it almost led to an Aberdeen goal after another break and cross ended with a Cosgrove shot being deflected wide.
With half an hour gone Aberdeen were on top but the home side were still making them work very hard.
On 31 minutes Lewis Smith was able to fire in a shot from 20 yards which Joe Lewis did well to tip over the bar. A minute later Lewis Ferguson went to down with a head knock but thankfully he was able to continue.
In the 36th minute a wonderful pass from Greg Leigh set McGinn free down the left. Niall got to the by-line but frustratingly his cut back went between Cosgrove and Hedges who were waiting inside the area.
With five minutes of the half to go McGinn whipped in a cross which Cosgrove flicked towards goal and Fon Williams just managed to keep it out at the second attempt.
Niall was giving right back Scott Martin a really tough time of it and crosses were coming in at will from that side. It was obviously an area the Dons had targeted as they were loading up that side.
Aberdeen though had another scare when Accies bulldozed their way into a central area and Ross Cunningham pulled his shot inches wide.
On the stroke of half time McGinn cut in off the left side and his curling effort crashed off the cross bar. He was so unlucky. The Dons then had a loud penalty shout for hand ball before Willie Collum blew for half-time.
Half time: Hamilton Accies 0 Aberdeen 1
At half time Craig Bryson was replaced by Dean Campbell. This allowed Ferguson to push further forward.
Two minutes after the restart a Hedges cross found its way to Ferguson and although his shot did not have much power on it, the ball bounced up in front of the keeper who could only palm it out. McGinn pounced but his shot somehow beat the keeper and went past the far post.
In the 50th minute Cosgrove won a free kick 20 yards out. Although McGinn eyed it up Ferguson took it and his low shot deflected off the wall and wide. From the resulting corner Hamilton cleared and were able to break. Dean Campbell was penalised with a yellow card for breaking up the move illegally.
On 52 minutes Scott McMann got on the end of a corner but thankfully his header went over the cross bar.
Aberdeen should have been awarded a penalty for hand ball but somehow the referee and the linesman failed to spot it. Ferguson's cross clearly struck a hand before the same player chipped a cross off the bar and Cosgrove was just the wrong side of the defender and could not get the ball as it bounced down.
The Dons were well on top now but needed a second goal.
On the hour mark Fon Williams could only push away a cross and Lewis Ferguson so nearly scored with a spectacular overhead kick, Scott McMann only just managed to head the ball to safety. Then from a corner McKenna had a spectacular effort which was just blocked.
Aberdeen have been here before at Hamilton shooting into that goal - doing everything but scoring.
On 61 minutes Ross Cunningham was booked for pulling back Logan. At the same time Lewis Smith was replaced by David Moyo. Hamilton's change of shape brought them back into the game.
In the 70th minute Sam Stubbs, the last defender and Cosgrove had a real battle for the ball and Aberdeen appealed for a penalty when Sam went down inside the area before McGinn fired a shot wide. On 73 minutes Hedges was replaced by Connor McLennan.
With fifteen minutes to go Ross Cunningham was replaced by striker Steve Davies as the home side went for it and they started to go long. With ten minutes to go another Aberdeen free kick bounced around the six-yard box but Leigh could not get a touch. It was amazing that they had so many entries into the penalty area, but the ball would not break kindly.
A minute later Cosgrove got up brilliantly and his header flicked off the bottom of the post with the keeper stranded.
The game became very scrappy in the final stages as the Dons struggled to enjoy any decent possession. It became nervy. Hamilton won a series of free kicks in good areas, it was a hard watch but credit to the Aberdeen players they battled hard, stood up to the physical challenge and claimed a very well deserved three points.