Adams shaped early American foreign policy using his ardently nationalist commitment to U.S. republican values. As a diplomat, Adams played an important role in negotiating key treaties, most notably the Treaty of Ghent, which ended the War of 1812 (1812–1815). As Secretary of State, he negotiated with Great Britain over the United States' northern border with Canada from the Great Lakes to the Rocky Mountains in 1818, negotiated with Spain the Adams–Onís Treaty, which allowed for the annexation and purchase of Florida from the Spanish, and drafted the "Monroe Doctrine", under fifth president James Monroe. Historians generally concur that he was one of the greatest diplomats and secretaries of state in American history. In his biography, Samuel Flagg Bemis argues that Adams was able to "gather together, formulate, and practice the fundamentals of American foreign-policy – self-determination, independence, noncolonization, nonintervention, nonentanglement in European politics, Freedom of the Seas, [and] freedom of commerce."
After leaving office, he was elected as U.S. Representative from Massachusetts in 1830, serving for the last 17 years of his life with greater acclaim than he had achieved as president. Animated by his growing revulsion against slavery, Adams became a leading opponent of the Slave Power. Adams predicted the Union's dissolution over slavery, and in such a case, felt the president could abolish slavery by using his war powers. Adams also became a critic of the annexation of Texas and the Mexican–American War, which he saw as an aggressive war for territory.
dams was elected president in a close and controversial four-way contest in 1824. As president he sought to modernize the American economy and promote education. Adams enacted a part of his agenda and paid off much of the national debt. However, he was stymied time and again by a Congress controlled by opponents, and his lack of patronage networks helped politicians sabotage him.