The lyrics come from `` Defense of Fort M'Henry '' , a poem written in 1814 by the 35-year-old lawyer and amateur poet , Francis Scott Key , after witnessing the bombardment of Fort McHenry by British ships of the Royal Navy in Chesapeake Bay during the Battle of Fort McHenry in the War of 1812 .
Francis Scott Key wrote the words to it in 1814 after seeing British ships attacking Fort McHenry in Baltimore , Maryland during the War of 1812 .