Gallagher, 30, becomes the second SPFL star after Celtic captain Scott Brown to agree to join Stephen Glass’ revolution in the north east.
A statement on the Motherwell FC website read: “We thank Declan for his contributions across the last two years.
“We will wish him well for the remainder of his career when he departs.”
Meanwhile, Aberdeen manager Glass welcomed the signing as he looks to mould the first-team squad in his own image after taking over from long-term boss Derek McInnes last month.
He told the club’s website: “We are delighted to be able to add someone of Declan’s quality to the first team.
“He is one of the country’s top centre backs and played a prominent role in Scotland’s qualification for the Euros this summer.
“Declan was highly sought after and we beat off stiff competition to get him here, but it’s really encouraging to see he believes Aberdeen is the correct place for the next stage of his career and we are eagerly looking forward to working with him when he arrives in the summer.”
Gallagher has been a ’Well player since signing a pre-contract deal in April 2019 following a successful spell with Livingston.
He spent almost five years with the West Lothian club, though he was imprisoned for over a year after being found guilty of assault.
His impressive form at Fir Park earned him a Scotland call-up in October 2019. He’s since made seven appearances for Steve Clarke’s side and may feature at this summer’s European Championships.
The centre back missed some ’Well matches in February due to a muscle injury.
After playing in the crucial 2-1 win at Ross County on January 27, Gallagher was absent for the 2-1 home success over Dundee United on February 3, and also missed subsequent games against Celtic (1-2), Kilmarnock (1-0), Hamilton 1-4, St Johnstone (0-3) and St Mirren (0-0) before returning as a substitute in the 2-0 league win at Hibs on February 27.