His predecessor, David Tomchak, left government this month to become digital director of editorial at the Evening Standard.
Hamilton had been with McCann for less than two years, working on digital and social campaigns for clients such as Microsoft, Nestle, and MasterCard.
His new job, which he starts on 30 May, marks a return to the public sector for the BBC veteran.
Prior to moving into the commercial sector, Hamilton spent 14 years at the public service broadcaster, including four years as head of social media for BBC News.
He describes himself as a "content and digital media specialist" who is an "expert in telling compelling stories that resonate with tens of millions of people every day" as well as being a "champion of innovation and creativity."
In a post on his Linkedin page this week, Hamilton said: "After a fascinating near two-year ride at McCann London, I'm changing gear slightly and heading to the civil service – or 10 Downing Street and the Cabinet Office to be precise. Can't wait to get stuck in."
His new role will see him head up the digital marketing team and the "regions and nations" campaigns team from the Prime Minister's Office and Cabinet Office, as part of the Government Communication Service (GCS).
Hamilton will also lead on "paid, owned and earned digital standards" and help "define and implement content, data, insight and buying strategies," according to a GCS announcement about his appointment.
He will head the cross-government Centre of Expertise, which is focussed on raising the standard of digital marketing in all departments, and be responsible for the "GCS Local" team of communicators and researchers based around the country.
Click here to subscribe to the new FREE public sector bulletin to receive dedicated public sector news, features and comment straight to your inbox.