St. Louis was transferred to the Republic of France in 1800, then sold to the United States in 1803 as part of the Louisiana Purchase. The city became the territorial capital and gateway to the western territory. Shortly after the purchase, the Lewis and Clark Expedition left St. Louis in May 1804 to explore the vast territory, reaching the Pacific Ocean in summer 1805, and returning on September 23, 1806. Both Lewis and Clark lived in St. Louis after the expedition. Many other explorers, settlers, and trappers (such as Ashley's Hundred) would later take a similar route to the West. The city elected its first municipal legislators (called trustees) in 1808.
Steamboats first arrived in St. Louis in 1818, improving connections with New Orleans and eastern markets. Missouri was admitted as a state in 1821, in which slavery was legal. The capital was moved from St. Louis to a more central location. St. Louis was incorporated as a city in 1822, and continued to see growth due to its port connections. Slaves worked in many jobs on the waterfront as well as on the riverboats. Given the city's location close to the free state of Illinois and others, some slaves escaped to freedom. Others, especially women with children, sued in court in freedom suits, and several prominent local attorneys aided slaves in these suits.