Alaska was claimed by Russia in 1795. They set up fur trading and attempted a colonization but it never really got going. But they got some trading towns set up along the coast. The U.S. owned the land to the south and British Canada owned land to the west.
The Treaty of Saint Petersburg (aka Anglo-Russian Convention of 1825) established the western border between Russia and the British. That set the border along the 141st line of longitude, but Russia also got to keep the coast (although the exact border was not well defined).
The Russo-American Treaty of 1824 (aka Convention Between the United States of America and His Majesty the Emperor of All the Russians, Relative to Navigating, Fishing, Etc., in the Pacific Ocean) set the U.S. northern border at the parallel 54 40’ North. That is the southern tip of Alaska. That basically set the shape of Alaska. The U.S. bought Alaska from Russia in 1867.
The western border of the panhandle was not clearly defined. Nobody seems to have cared too much until gold was discovered. It was settled by arbitration in 1902-03. The British caved to the U.S. and Canada didn’t get a convenient port for the gold mines. That contributed to grumbling from Canadians about their British affiliation.