As the evening of September 13, 1814, approached, Francis Scott Key, a young lawyer who had come to negotiate the release of an American friend, was detained in Baltimore harbor on board a British vessel. Throughout the night and into the early hours of the next morning, Key watched as the British bombed nearby Fort McHenry with military rockets. As dawn broke, he was amazed to find the Stars and Stripes, tattered but intact, still flying above Fort McHenry.
…Key’s experience during the bombardment of Fort McHenry inspired him to pen the words to “The Star-Spangled Banner.” He adapted his lyrics to the tune of a popular drinking song, “To Anacreon in Heaven,” and the song soon became the de facto national anthem of the United States of America, though Congress did not officially recognize it as such until 1931.
The Smithsonian Institution, which has the original “star-spangled banner,” has details about the flag.