By 1800, Spain was in debt because they participated in wars that were caused by the French Revolution. Although they didn't like it, Spain had to return Louisiana to the expanding France. Giving Louisiana would offer better protection to Mexico and lower Spain's debt. In 1801, the Treaty of San Ildefonso was signed and Lousiana was now France's.
*Sigh* I have signed the treaty, Louisiana is now yours.
Oui Oui, we are now more powerful!
Thomas Jefferson caught wind of the rumors circulating around the treaty. Jefferson knew that France could revoke access to the Mississippi River and New Orleans which could impact American society critically. Jefferson started a diplomatic campaign to get New Orleans from France.
ARGH! We need New Orleans or our nation will crumble!
We will try our best to figure out a plan to conquer this problem, sir.
*Neigh*
Napoleon Bonaparte envisioned a powerful French Empire and acquiring Louisiana propelled his dream. Bonaparte needed Saint-Domingue for his empire, but it was covered in revolution. In the fall of 1802, Bonaparte realized that success in Saint-Domingue can't be found without more resources, so he and his troops withdrew. Bonaparte had no use for Louisiana so he sold it.