What event inspired Francis Scott Key to write "The Star-Spangled Banner"?

The event that inspired Francis Scott Key to write "The Star-Spangled Banner" was the Battle of Baltimore during the War of 1812. Specifically, Key was inspired by the sight of the American flag still flying over Fort McHenry after a bombardment by the British naval forces. This event, witnessed by Key on September 14, 1814, became the basis for the lyrics of the national anthem.