In May 1862, he became a U.S. Commercial Agent in Liberia and on June 8, 1863, he was appointed by President Abraham Lincoln to become the first U. S. Commissioner/Consul General to Liberia. The United States Senate confirmed the appointment on January 12, 1864. He presented his credentials to the Liberian government on February 23, 1864. In 1866, Hanson became ill during his diplomatic service. He died on July 20, 1866, and was buried in Monrovia, the Liberian capital.