The 25-year-old former Kilmarnock and Everton player will remain with Saints until the end of the season before making the switch to Pittodrie.
Dons boss Derek McInnes told the club website: "I’m pleased Matty has shown a real desire to join Aberdeen when there were other options available to him."