On September 3, 1814, Francis Scott Key and John S. Skinner, an American prisoner-exchange agent, set sail from Baltimore aboard the ship HMS Minden flying a flag of truce on a mission approved by President James Madison. Their objective was to secure the release of Dr. William Beanes, the elderly and popular town physician of Upper Marlboro, and a friend of Key’s who had been captured in his home. Beanes was accused of aiding the arrest of British soldiers. Key and Skinner boarded the British flagship HMS Tonnant on September 7 and spoke with Major General Robert Ross and Admiral Alexander Cochrane over dinner, while they discussed war plans. At first, Ross and Cochrane refused to release Beanes, but relented after Key and Skinner showed them letters written by wounded British prisoners praising Beanes and other Americans for their kind treatment.
<snip>
Key was inspired by the American victory and the sight of the large American flag flying triumphantly above the fort. This flag, with fifteen stars and fifteen stripes, came to be known as the Star Spangled Banner Flag and is today on display in the National Museum of American History, a treasure of the Smithsonian Institution. It was restored in 1914 by Amelia Fowler, and again in 1998 as part of an ongoing conservation program.
Aboard the ship the next day, Key wrote a poem on the back of a letter he had kept in his pocket. At twilight on 16 September, he and Skinner were released in Baltimore. He finished the poem at the Indian Queen Hotel, where he was staying, and he entitled it "Defence of Fort McHenry."
Key gave the poem to his brother-in-law, Judge Joseph H. Nicholson. Nicholson saw that the words fit the popular melody "To Anacreon in Heaven", an old British drinking song from the mid-1760s, composed in London by John Stafford Smith. Nicholson took the poem to a printer in Baltimore, who anonymously printed broadside copies of it – the song’s first known printing – on September 17; of these, two known copies survive.
http://en.wikipedia.org/wiki/The_Star-Spangled_Banner