Sweeney spent three seasons with the Stags playing 127 games, scoring seven goals, and also had spells captaining the side.
“I am delighted to have signed for Dundee and can’t wait to get going and looking forward to the new challenge,” he said.
Sweeney began his career with AFC Wimbledon and broke into the first team before transfer to Stoke City in 2016.
While under contract at Stoke, he spent two loan spells at Bristol Rovers before a season on loan at Mansfield and a permanent move to them in 2019.
Sweeney also has nine caps for Republic of Ireland Under 21s.