He was elected as a councillor to the City of Leeds Council in 1987, stepping down eleven years later in 1998. He was elected as the chairman of the Leeds West Constituency Labour Party in 1987, and he contested Leeds North East at the 1992 general election but was defeated by the sitting Conservative MP Timothy Kirkhope by 4,244 votes, gaining a 5.9% swing from the Conservative Party to Labour.
Despite having achieved the highest Labour swing in the North of England, Hamilton's local constituency voted (by a margin of one vote) in favour of an all-women shortlist. At the time Hamilton was quoted by The Independent as saying:
"For six years, I was chair of Leeds city council's equal opportunities committee. Equal ops was my life. And to find that, as far as the Labour Party is concerned, equal opportunity now means positive discrimination, came as a real shock to me. I am told that my generation of men will just have to stand back and make way for women. And I understand why certain women in the Party have pushed that policy. But I think they're wrong. What they don't seem to take on board is that I've only got one life, too. I didn't choose my time on earth any more than I chose my sex or my race. And I really mean it when I say that being kept out of a job just because I'm a man offends me as deeply as being kept out of a job just because I'm a Jew."
He was elected to the House of Commons at the 1997 general election when he defeated Kirkhope in a re-run at Leeds North East by 6,959 votes and has remained the MP there since. He made his maiden speech on 23 June 1997, in which he explained that his constituency stretches from the inner-city Leeds district of Chapeltown all the way out to Harewood House, the stately home of the Earls of Harewood.
He is said to be the first MP to hold a virtual surgery for constituents: local people go to his constituency office while he is in London, and converse via webcam.
Hamilton is a signatory of the Euston Manifesto and the Henry Jackson Society. He was a signatory of an open letter to the then-Labour Party leader Edward Miliband in January 2015 calling on the party to commit to oppose further austerity, take rail franchises back into public ownership and strengthen collective bargaining arrangements He supports Labour Friends of Israel and was critical of Ed Miliband's stance on the Israel-Gaza conflict in 2014.
In Parliament he served as a member of the Administration Select Committee 1997–2001, and has been a member of the Foreign Affairs Select Committee since the 2001 general election. He is also the chairman of the all party groups on business services, prison health, and civil contingency, he also serves as the vice-chairman of the all-party Iran group. He also chairs the All-Party Parliamentary Group for Tibet.
On 7 January 2016 Hamilton was appointed a shadow Foreign Minister, outside the Shadow Cabinet.
On 8 November 2016, Corbyn fulfilled a campaign pledge as Hamilton was appointed as Shadow Minister for Peace and Disarmament. The role covers North Africa, the Middle East, North Korea and Labour Party policy on nuclear weapons.