"It was a wee bit harsh on Hamilton," admitted Aberdeen manager Jimmy Calderwood.
"They caused us numerous problems and we were lucky to get away with it.
"It was very even and it took a touch of class from Barry Nicholson to open them up."
Calderwood will be without Nicholson in the next round after the midfielder picked up his second booking of the tournament.
Hamilton got a late cup reprieve when Brechin were thrown out for fielding two ineligible players.
And the visitors started the game well, with Langfield tipping away a shot from Gilhaney and Offiong chipping over.
Aberdeen responded with a Richard Foster shot that was held by Bryn Halliwell and Josh Walker curled a 20-yard free-kick inches wide.
Accies came close in the 15th minute when Stevenson headed Tom Parratt's cross against the outside of the post.
Langfield then blocked Graham's low shot from 15 yards after James McCarthy's return pass had cut open the Dons.
Halliwell parried Andrew Considine's swerving long-range effort and Jeffrey de Visscher's shot from just inside the box was deflected wide.
Brian Easton smashed in a shot from 20 yards out, which Langfield turned past the post. Easton then had two efforts blocked in a frantic goalmouth scramble following the corner.
The game was won when Nicholson's brilliant pass split the Accies defence and Diamond slotted in off the post despite Halliwell getting a touch.
Hamilton fought back and Stevenson had a powerful shot blocked at the near post before Offiong headed just wide of the top corner.
Hamilton pushed forward and were almost caught on the break when Derek Young released Walker, but the on-loan teenager shot straight at Halliwell.
Mark McLaughlin headed wide from Parratt's cross before Langfield pulled off a late, last-ditch save from James Grady after the veteran striker had latched on to a long ball.
"I can't fault any of my players," Accies boss Billy Reid told BBC Sport. "They gave me everything.
"Our shape was good and we defended well, although we didn't have much to do at the back.
"We passed it well and our front three looked sharp. We looked a threat every time we went up the park."
Aberdeen
: Langfield, Duff (Maybury 69), Diamond, Considine, Foster, De Visscher (Young 45), Nicholson, Severin, Walker, Mackie (Lovell 79), Miller. Subs Not Used: Soutar, Maguire.
Booked
: Nicholson, Miller, Walker.
Goals
: Diamond 62.
Hamilton Academical
: Halliwell, Parratt, McLaughlin, Stevenson, Easton, Graham (Waterworth 81), Mensing, McArthur, McCarthy, Gilhaney (Grady 72), Offiong. Subs Not Used: Cerny, Gibson, Barrau.
Booked
: Parratt.
Att:
6,441
Ref
: Douglas McDonald