He served in the Maine House of Representatives from 1836 to 1841 then two terms in the U.S. House of Representatives (1843-1847). He was elected to fill a Senate vacancy in 1848 and to a full term in 1851.
A Democrat, Hamlin supported the candidacy of Franklin Pierce in 1852. However, he broke with the party over pro-slavery Democratic policies, and on June 12, 1856, he left the party and joined the Republicans. This caused a national sensation.
That same year Hamlin was elected the first Republican governor of Maine, but served less than a month before returning to the Senate. He was chosen for the second place on the Republican ticket in 1860. His identification with Radical elements of the party caused him to be dropped from the ticket in 1864.
He had two sons, Charles Hamlin and Cyrus Hamlin, who served in the Civil War. Charles and sister Sarah were present at Ford's Theater the night of Lincoln's assassination. His son Hannibal Emery Hamlin was Maine state attorney general from 1905 to 1908.
There are biographies by his grandson Charles E. Hamlin (printed 1899, reprinted 1971) and H. D. Hunt (printed 1969).