Why did Francis Scott Key write "The Star-Spangled Banner"

Francis Scott Key wrote "The Star-Spangled Banner" after witnessing the British bombardment of Fort McHenry during the War of 1812. Key, who was a lawyer and amateur poet, was on a British ship negotiating the release of American prisoners when the attack on Fort McHenry took place. Inspired by the American flag still flying proudly over the fort after the bombardment, Key wrote the poem that would later become the lyrics for the national anthem of the United States. The poem was initially published under the title "Defense of Fort M'Henry" in 1814 and gradually gained popularity, eventually becoming the official national anthem in 1931.