He left the Senate in 1794 to serve as President George Washington's ambassador to France but was recalled by Washington in 1796. Monroe won the election as Governor of Virginia in 1799 and strongly supported Jefferson's candidacy in the 1800 presidential election.
As President Jefferson's special envoy, Monroe helped negotiate the Louisiana Purchase, through which the United States nearly doubled in size. Monroe fell out with his longtime friend James Madison after Madison rejected the Monroe–Pinkney Treaty that Monroe negotiated with Britain. He unsuccessfully challenged Madison for the Democratic-Republican nomination in the 1808 presidential election, but in 1811 he joined Madison's administration as Secretary of State. During the later stages of the War of 1812, Monroe simultaneously served as Madison's Secretary of State and Secretary of War. Monroe's wartime leadership established him as Madison's heir apparent, and he easily defeated Federalist candidate Rufus King in the 1816 presidential election.
During Monroe's tenure as president, the Federalist Party collapsed as a national political force and Monroe was re-elected, virtually unopposed, in 1820. As president, Monroe signed the Missouri Compromise, which admitted Missouri as a slave state and banned slavery from territories north of the 36°30′ parallel. 