During the War of 1812, on September 13, 1814, Francis
Scott Key visited the British fleet in Chesapeake Bay to secure
the release of Dr. William Beanes, who had been captured after
the burning of Washington DC. The release was secured, but Key
was detained on ship overnight during the shelling of Fort McHenry,
one of the forts defending Baltimore. In the morning, he was
so delighted to see the American flag still flying over the fort
that he began a poem to commemorate the occasion. Entitled "The
Star Spangled Banner", the poem soon attained wide popularity
as sung to the tune "To Anacreon in Heaven". The origin
of this tune is obscure, but it may have been written by John
Stafford Smith, a British composer born in 1750. "The Star
Spangled Banner" was officially made the National Anthem
by Congress in 1931, although already adopted as such by the
Army and Navy.
Reference: Embassy of the United States of America, Ottawa,
Canada