The Louisiana Territory changed hands several times before the United States purchased it. The French were the first who claimed the territory. But just as Pierre Laclede was establishing the new village of St. Louis in 1763, they received word that France had actually ceded the Louisiana Territory to the Spanish by secret treaty in 1762. French officials remained in authority until Spain officially took control of the Louisiana Territory in 1770 when the Spanish lieutenant-governor, Don Pedro Piernas, arrived. In 1800 Spain was forced by Napoleon in a secret treaty to return the Louisiana Territory back to France.
It was in 1802, that it became apparent to Napoleon that his dream of extending his French Empire to include the Louisiana Territory was not going to become a reality. At the same time, President Thomas Jefferson had sent ministers to negotiate for the purchase of New Orleans from the French because the Spanish, who were still in authority, had closed this important river port to the Americans. Napoleon's ministers surprised the Americans by not only agreeing to sell New Orleans, but also offering to sell the entire Louisiana Territory to the United States! Thus, in April of 1803, the land that the City of St. Louis sits on today, was acquired by the United States in the Louisiana Purchase.
The transfer of St. Louis to the Americans took place on two days in March of 1804 in a ceremony that is referred to as "Three Flags Day". Since the Spanish had never given up authority of St. Louis to the French back in 1800, the Spanish flag went down on March 9th and the French flag went up for one night representing the transfer of the Territory from Spain to France. Then on the morning of the 10th, the French flag came down and the United States flag went up representing the transfer of the Territory from France to the United States.
The Louisiana Purchase nearly doubled the land of the United States, allowed the free navigation of the entire Mississippi River and opened "the floodgates" of westward expansion with the City of St. Louis acting as the "gateway".