The almost 200-year old, 30-by 34-foot flag that inspired Francis Scott Key to write the US National Anthem on August 11, 2010 at the Smithsonian Institutions American History Museum in Washington, DC. (TIM SLOAN/AFP/GETTY IMAGES)

As the Washington area marks the bicentennial of the War of 1812, an excerpt from the Book “Through the Perilous Fight:Six Weeks That Saved the Nation” by Steve Vogel, coming out Tuesday. This excerpt is how “The Star-Spangled Banner” came to be.

The sudden quiet in the predawn darkness was terrible for Francis Scott Key and the other Americans watching the bombardment of Fort McHenry from the deck of a ship anchored in the Patapsco River. Had the British attack been abandoned, or had the fort surrendered?

The star-shaped brick fort guarding Baltimore from an invading British force had been brutally bombarded for almost a full day and full night. During the last several hours, beginning shortly after midnight Tuesday, Sept. 13, 1814, the bomb ships Devastation, Terror, Volcano, Aetna and Meteor had opened up on Fort McHenry with unmatched fury. “The hissing rockets and the fiery shells glittered in the air, threatening destruction as they fell,” recalled a young British midshipman aboard a frigate.

Cover of Steve Vogel's "Through the Perilous Fight: Six Weeks That Saved the Nation." (Book design by Caroline Cunningham/Book design by Caroline Cunningham)

The ground shook at Fells Point in Baltimore Harbor, where terrifying rumors swept through the streets that the British had taken the fort and were on the way to burn the city. The rain fell in torrents, accompanied by terrific flashes of lightning and rumbles of thunder. “The portals of hell appeared to have been thrown open—the earth and air, nay all the elements, seem to have been combined for the destruction of man,” a resident watching from his rooftop wrote in trembling hand to his wife.

In the twilight evening, Key had seen a large American flag still flying over Fort McHenry. Once night fell, he could no longer see the flag, but the continuing bombardment was proof enough that the fort had not surrendered. But now, the eerie predawn silence Wednesday morning offered no such reassurance.

* * *

Like many Americans, Key, a 35-year-old Washington lawyer, was fervently opposed to the war the United States, angered over violations of American sovereignty, had declared on Britain in 1812. In part, this reflected his devout Christianity, and in part, his cultural affinity with England. Most of all, Key could not abide the idea that his country would attack the British colonies in Canada — innocent third parties, in his view — to settle its grievances with Great Britain.

After British victories on the Canadian front in the fall of 1813 forced the United States to abandon its plans to capture Montreal, he shared his delight with John Randolph, the former House representative from Virginia and his closest friend.

“This I suppose is treason, but as your Patrick Henry said, ‘If it be treason, I glory in the name of traitor,’ ” Key wrote. “I have never thought of those poor creatures without being reconciled to any disgrace or defeat of our arms.”

Yet Key, living in Georgetown with his wife and six young children, felt quite differently about his homeland being invaded. When the British terrorized the Chesapeake in the summer of 1813, burning towns and plantations, he volunteered with the local militia.

As the war entered its third year, Key’s sense of foreboding grew. “We see what other nations have suffered — shall we escape so much more lightly?” Key wrote Randolph on Aug. 10, 1814. The answer came two weeks later, when the British routed an American force defending Washington and burned the White House and Capitol; light from the tremendous fires was visible as far away as Fredericksburg and Baltimore.

A few days later, Key and American prisoner-of-war agent John Skinner sailed to the British fleet in the Chesapeake under a flag of truce to negotiate the release of William Beanes, an elderly doctor held captive by the enemy. The British agreed to free the doctor, but detained all the Americans until they completed their attack on Baltimore. Key and his party watched helplessly as the British launched dual assaults on the city by land and water.

* * *

Key and Skinner paced the deck of their truce ship in painful suspense early Wednesday morning, anxiously awaiting the return of day. Finally, the first pale signs of dawn brightened the sky. They trained their glasses on the fort, as Key later told his brother-in-law, Roger Brooke Taney, “uncertain whether they should see there the stars and stripes, or the flag of the enemy.”

Through the morning mist, the Americans finally could make out a flag, towering over the grassy knoll of the ramparts. But the banner hung limply from the flagpole, and it was impossible to tell if it was American or British.

A slight breeze blew fitfully from the northeast, scattering the mist. The flag stirred with a tantalizing hint, but Key and Skinner remained unsure. Finally a beam of sun illuminated the flag, revealing it to be American.

As the morning brightened, Key’s hopes soared at every sign of British retreat. The bombardment squadron sullenly sailed downriver. A stream of small boats came down Bear Creek, carrying wounded British Army soldiers and Royal Marines from the Patapsco Neck, where they had fought a land battle with Maryland militia defending the city.

Inspiration, Key told Taney, came “in the fervor of the moment.” For a man who had spent his life scribbling poems and verse for every occasion, it was a natural impulse. “[I]n that hour of deliverance, and joyful triumph, the heart spoke,” Key recalled many years later.

He pulled a letter from his pocket and wrote some notes on the back.

Patapsco River, Sept. 16

As the truce ship sailed toward Baltimore that evening, Key worked on his composition. He was writing a song, not a poem.

Later, the myth would take hold that Key’s words were adapted to song by an alert singer who noticed that the words coincidentally matched “To Anacreon in Heaven,” a well-known tune of the day. Yet the evidence is clear that Key had that tune in mind from the start.

Written in London around the time of the American Revolution, “Anacreon” was an old American standard by 1814. It is often referred to dismissively as “a drinking song,” a misleading label. The Anacreontic Society was a popular and convivial gentleman’s club in London named after the sixth-century B.C. Greek poet Anacreon, whose verse celebrated the joys of wine and women.

The society’s meetings often featured a concert with some of the best performers in London. After the music, an elegant supper was served, then all members would join in singing lighthearted songs. The first song was always the club’s constitutional song, “To Anacreon in Heaven,” whose words had been written by the club president, Ralph Tomlinson, a London attorney.

Music to accompany the four verses was written around 1775 by another member of the society, John Stafford Smith, an accomplished organist, tenor singer and composer from Gloucester. The society members wanted a song that would both challenge and show off their vocal range, and “Anacreon” fit the bill.

The song’s popularity soon spread across the Atlantic, where various Anacreontic societies were established, including one in Baltimore. Songwriters continually adapted new words to the melody, and by 1814, no fewer than 85 versions had been published in the United States.

There is no doubt Key was quite familiar with the melody. He had used the tune for a song he had written nine years earlier saluting Navy Lt. Stephen Decatur for his heroism during the first Barbary War. At Tripoli harbor in February 1804, Decatur boarded the captured USS Philadelphia with U.S. Marines, set fire to the ship, and escaped under a hail of fire. Decatur was celebrated across America.

Key viewed it as not only a triumph against pirates, but also a victory of Christianity over Islam. When a dinner party was thrown in Georgetown on Nov. 30, 1805, in honor of Decatur, Key wrote a song for the occasion. Titled “When the Warrior Returns From the Battle Afar,” it was sung to the tune of “Anacreon.”

The third verse included this couplet:

And pale beamed the Crescent, its splendor obscured,

By the light of the star-spangled flag of our nation.

The song was printed in several newspapers, including the Boston Independent Chronicle. Though inferior to the song that would follow nine years later, “Warrior” contains the unmistakable genesis of “The Star-Spangled Banner,” showing metric agreement and similar phrasing. It guided Key as he composed his new song.

* * *

Once the excitement died, Key took lodging a few blocks away at the Indian Queen Tavern, at the corner of Market and Hanover streets. That night in his room, he picked up a pen and paper to write his song longhand. The notes written on the back of the letter served as the basis for much of his composition. But for some of the lines, as Taney recounted, “he was obliged to rely altogether on his memory.”

“O say can you see through” — Key paused here, scratched out “through” and substituted “by,” then continued: “the dawn’s early light.” The verse, when completed, asked one long question:

O say can you see by the dawn’s early light

What so proudly we hail’d at the twilight’s last gleaming

Whose broad stripes & bright stars through the perilous fight

O’er the ramparts we watched were so gallantly streaming?

And the rocket’s red glare, the bombs bursting in air

Gave proof through the night that our flag was still there

O say does that star spangled banner yet wave

O’er the land of the free & the home of the brave?

The question mark at the end of the verse, H.L. Mencken later noted, is essential to understanding Key’s meaning, revealing “the poet is not at all sure that the Republic will survive.” The second verse carries the answer, describing the tension at dawn as Key and his companions tried to make out what flag was flying:

On the shore dimly seen through the mists of the deep,

Where the foe’s haughty host in dread silence reposes,

What is that which the breeze, o’er the towering steep

As it fitfully blows, half conceal, half discloses?

Now it catches the gleam of the morning’s first beam

In full glory reflected now shines in the stream,

Tis the star-spangled banner, O! long may it wave

O’er the land of the free and the home of the brave

In the third verse, Key’s disgust with the British spilled out, and his language took on uncharacteristically angry and vengeful tones, reflecting the emotion of the moment.

And where is that band who so vauntingly swore

That the havoc of war and the battle’s confusion,

A home and a country, shall leave us no more?

Their blood has washed out their foul footsteps pollution

No refuge could save their hireling and slave,

From the terror of flight or the gloom of the grave

And the star-spangled banner in triumph doth wave

O’er the land of the free & the home of the brave

“Hireling” apparently refers to professional British soldiers fighting for money, unlike the American militia volunteers defending Baltimore. Key’s use of “slave” may be a reference to the Colonial Marines, escaped slaves who had joined the British forces; an ironic choice of words if so, as they were fighting for their freedom.

Key took a more pious tone with his fourth verse. His song was ultimately a hymn, a prayer of thanks to God for saving the city, and this is most evident in the final verse.

O thus be it ever when freemen shall stand

Between their lov’d home & the war’s desolation;

Blest with vict’ry and peace, may they heav’n rescued land

Praise the power that hath made and preserved us a nation!

Then conquer we must, when our cause it is just,

And this be our motto—“In God is our trust.”

And the star-spangled banner in triumph shall wave

O’er the land of the free & the home of the brave.

* * *

When Skinner called on Key Saturday morning, the latter showed him the composition. Skinner was impressed—it captured the long night and the coming of dawn perfectly.

Key went next to the home of his sister-in-law to check on her husband, Joseph Nicholson, who commanded a volunteer artillery company at Fort McHenry. Two of Nicholson’s men had been killed during the bombardment, and several more severely wounded. Reading the song, Nicholson was profoundly moved, and wanted it shared with the public.

Either Nicholson or Skinner—or possibly the two working together—took the composition to the office of Baltimore American that day to be set as a handbill.

Hundreds of copies of “Defence of Fort M’Henry,” as it was named, were delivered to the fort, and it was quite popular with the garrison.

At least one printed copy made it into Key’s hands before he left town Saturday, anxious to reunite with his family.

Key had no way of knowing that in a single night, he had written what would become the United States’ national anthem, as well as coined a motto for the nation: “In God We Trust.” Yet on his journey home, he must have felt satisfied.

Related: Q&A: The Star Spangled Banner, Francis Scott Key and the War of 1812

2013 by Steve Vogel. Reprinted by arrangement with Random House. All rights reserved.