It is the autumn of 1814. The British army has just burned Washington and is shelling Baltimore. Next, it is invading from the north along Lake Champlain.

The U.S. Treasury is empty, and the department is defaulting on its war bonds. In Philadelphia, New York, and Boston, bankers are sending their gold and silver to Canada to transship to Britain. In Amsterdam, bankers refuse to lend any more money to cover the expenses of the American diplomats in Ghent, Belgium, who are attempting to negotiate an end to the War of 1812.

In what Winston Churchill called "an unofficial trade war," confrontations between the United States and Britain have flared in fits and starts for 50 years. Revolutionary War combat gave way to decades of toxic internal political turmoil and, finally, the resumption of bloody fighting on land and sea. And now, in 1814, the U.S. is bankrupt.

Today, it seems as if President Trump read the history of the post-revolutionary era and decided to reenact it: a refugee crisis, vitriolic politics, tensions over free trade, demonizing of foreigners amid allegations of  intrusion in America's internal affairs — self-perpetuating crises that brought the U.S. to the verge of collapse.

Revolutions in Europe had swamped America's coastal cities with refugees. The orgiastic French Revolution coupled with a slave revolt in the Caribbean sent as many as 5,000 refugees a month crowding into Philadelphia alone.

Francophobic President John Adams' Alien and Sedition Act sent the Supreme Court justices riding in carriages from city to city, scanning opposition newspapers for criticism of the administration and jailing their editors. French exiles were pressured to go home. Asked why one French émigré was being expelled, Adams replied, "Because he is too French."

As the French Revolution morphed into a global war between British and French empires, the U.S. attempted neutrality. But both European combatants and Algerian pirates seized American merchant ships. There was no Navy to protect them. Adams sent barrels of silver coins to Algeria to free hostages and built the first Navy ships to fight the French in the Caribbean.

When Alexander Hamilton sabotaged Adams' reelection campaign, pacifist Thomas Jefferson reversed Adams' policies, dismantling the Navy.

Despite outrageous trade restrictions imposed by the British, America's carry trade increased tenfold between 1790 and 1812. British ships began blockading American harbors, searching for French contraband and British deserters. Britain "impressed" 9,917 sailors — 40 percent had been born in England or Ireland. They had become U.S. citizens, but Britain scoffed at the American doctrine of naturalization. Born English, you died English.

Diplomacy unavailing, Jefferson tried coercion. He declared an embargo prohibiting maritime commerce with any foreign state. This drastic isolationist experiment proved catastrophic, in one year destroying 80 percent of America's import-export trade and bringing on the worst depression since the Revolution.

By the time James Madison became president, war fever had swept America. A War Hawk faction captured the off-year congressional elections, and Jefferson proclaimed that seizing all of Canada would be "a mere matter of marching." Three invasion attempts would fail miserably.

The Navy's 16 ships faced 651 battle-ready British men-of-war. But in the first year of conflict, the solitary victory of the USS Constitution — "Old Ironsides"  — over a British frigate buoyed pro-war Madison's reelection campaign.

The first American invasion of Canada, an amphibious operation against York (present-day Toronto), destroyed the provincial capital of Upper Canada. In a drunken rampage, Americans razed government buildings and looted homes and churches. One year later, a British army retaliated by burning Washington.

It was a war of raiding, burning, and plundering — and 20,000 Americans were killed. British officers pocketed fortunes in prize money, seizing and reselling ships. Without any real navy, American merchant marines financed, built, and armed about 2,000 privateering ships, many crewed by Irish refugees. They captured 1,500 British vessels.

Only a string of last-minute American victories — the defense of Baltimore by its citizens and the crushing defeat of a British squadron on Lake Champlain — led American and British leaders to come to terms in Ghent. Both sides were broke. Though neither had won a scrap of territory, Andrew Jackson's victory at New Orleans convinced Americans that at least they had not surrendered to Britain, as Napoleon soon would do at Waterloo.

Hurrying from peace talks to London, America's negotiators signed a "most-favored-nation" trade alliance, still in force today.

In an American revolutionary era much like today, the U.S. survived political turmoil, heavy-handed foreign meddling, financial collapse, and a series of refugee crises (by granting citizenship to all comers). The U.S. finally emerged economically as well as politically independent, in fact the world's leading independent maritime power. From the beginning of the half-century-long struggle, it was then — as it is now — all about free trade.

Willard Sterne Randall, the distinguished scholar in history and professor emeritus at Champlain College, is the author most recently of "Unshackling America: How the War of 1812 Truly Ended the American Revolution."