Dundee 2 Hamilton Academical 4
The visitors drew first blood and must now fancy their chances for Thursday night's re-match in the Scottish Cup quarter final.
The visitors got off to the perfect start when Paul McMullan crossed from the left and the ball was headed home by Brown Ferguson with just a minute on the clock.
Simon Lynch, Barry Smith and Garry Brady all had shots saved by Raymond Jellema inside the opening 15 minutes as Dundee tried to hit back.
All their efforts were in vain, however, as Hamilton doubled their lead after 22 minutes when Patrick Keogh easily brushed aside Callum McDonald in the Dundee area before firing low into the net from six yards.
Simon Lynch's close-range header was well saved by Raymond Jellema in the 55th minute.
As the visitors went in search of a third, Patrick Keogh's shot was well saved by Scott Murray before Rudy Torres fired wide from a tight angle.
The visitors wrapped up a fine victory with seven minutes remaining when Rudy Torres latched on to a long through ball and finished well, beating Scott Murray from eight yards.
Two minutes later Dundee grabbed a consolation when come-back man Lee Wilkie headed home from close range.
Any joy that Dundee had from that goal was short-lived as Brian Wake restored the visitors' three-goal lead a minute later.
The scoring hadn't finished yet, and Dundee scored again through Scott Robertson after 88 minutes.