A rough concept
As the Napoleonic Wars rage across Europe, the USA brings the Barbary pirates under control as in OTL. Meanwhile, the wars are grinding down to a stalemate. The wars are hurting American shipping enough that Congress votes funds for more light warships—sloops and a few small frigates join the 44’s. Each of them is built along the same general idea as the 44’s—expensive, but high quality ships. The quasi-war with France gives the Europeans a taste of American ship quality, and France backs down from harassing American shipping.
Trade with Britain continues for a time, although British impressment of American sailors is a continuing problem. Trade with North Africa soon begins to show a profit—the Barbary states have learned well that America isn’t at war—and will happily send another fleet if need be, but would rather trade.
By 1812, the Barbary powers are thriving with Europe at war.
When the War of 1812 breaks out, at first it goes mostly as in OTL—but Britain can’t manage to win the European war, and the USN has a few more minor victories at sea. Even more than in OTL, the war will be remembered by so many Americans as the war in which the USA humbled the Royal Navy, even though this isn’t the case at all.
The British decide to attack on New York to force the Americans to negotiate. The attack turns into a fiasco, as the wind dies, and the steam battleship Demologos destroys or captures the invasion force. (Demologos really existed, and IMHO, would be well able to devastate a sailing force in calm waters with no wind. Hot shot is nasty!)
The battles of New Orleans and New York are very costly—especially New York, with several ships of the line gone—and two flying the stars and stripes now.
In mid 1815, the two nations come to terms and sign the Treaty of Ghent..
All seized lands are returned, including certain chunks of Canada snatched in the spring of 1815. Britain also agrees that US ships have the right to trade wherever they see fit, provided the port is not under a formally declared blockade. (This clause will have SERIOUS repercussions 99 years later, as Europe explodes in flames once again,) In return, the US agrees to resume trade in war materials with Britain, and protect its own shipping. Impressment of Americans is formally renounced.
When the European wars finally grind to a close in 1817, most of Europe is a shambles. The Congress of Vienna divides Europe, but there’s still fear of more war, so no-one wants to invade Africa, nor is there the stomach for another fight. The American merchant marine has swollen hugely—American ships are common throughout the world. Merchants prefer to use them, knowing that even the Royal Navy will leave them alone, even in ports British ships are barred from entering.
By this time, the Barbary pirates have grown fat with both raiding and trading. They also have purchased three steam battleships for coast defense. They exact a minor tribute for a few years, only seizing the occasional merchant. They also soon become an international free port, where goods of questionable origin are bought and sold—they know that they have to be useful, or son, the Royal Navy will force them to shape up. This trend started when merchants would ship goods from one part of Europe to another, hiding the origins in Africa, so as to allow goods to bypass national borders.
By 1825, some of the European nations are growing weary of paying tribute—and envious of the USA, which is not similarly burdened. They still consider them possible allies should another war break out, but apply diplomatic pressure to reduce the tribute—threatening to smash one state or another “Pour encourager les autres.” At the time, the threats are just a bluff—oner that backfires horribly. The response shocks Europe—the formation of the Barbary Alliance. With a better bargaining position, some tribute continues to flow, but its becoming less important as trade continues to flourish.
By 1840, tribute is reduced even further, but the African coast still sees the occasional true pirate. Even now, though, the pirates are slow to attack American ships, as the Barbary governments are quick to hunt them down if they do—the modern weapons that they need come from American factories. Some of those modern weapons are more steamships—the world is going with steam power earlier than in OTL, having learned some lessons (some of them the wrong ones) from the Battle of New York. It’s still far cheaper to pay a small sum each year than to sponsor a major war. In addition, there is the annoying Anglo-American treaty concerning free passage of American ships. A close blockade would be difficult, and anything else would allow the US to ship supplies in—and trying to interdict them on the high seas could lead to the US getting into the war.
In the 40’s and 50’s, continuing efforts are made to get the USA to at least take a position, but to no avail. Ambiguity served the US far better—the European nations keep paying tribute, and the Barbary Alliance—now growing into a confederation—spends it in the USA. The Crimean War completely disrupts all attempts to end tribute, as various nations offer increased tribute to prey on enemy commerce.
Assuming butterflies don’t disrupt the timing, the American Civil War will be a definite hard time for the Barbary confederation. The supplies will dry up as the Northern factories are diverted to war production, and a negotiated end to the tribute finally occurs in 1861, provided there’s no war scares in Europe. More likely, tribute is reduced to a trickle—there’s always a perceived need for allies in a future war, and the tribute may be seen as buying friendship—or at least neutrality—down the road. Tribute treaties become more intricate, stating what the responsibilities of each power are in peace and war.
Confederation factories can’t fill the gap left by American factories, but the war encourages the Confederation to industrialize more—and rationalize its federated military. Industrialization is slow due to lack of money, but it proceeds.
The Civil War ends in 1864—early because the Union navy was larger and better equipped, and the factories were already producing weapons for the export market.
Now we’re up to 1864, with a Barbary confederation starting to industrialize, American industry becoming a major factor in the world economy, and the US slightly more involved in European affairs than before.
Assuming that nothing else changes, in 1914, Britain may really regret the treaty with the US that it signed in 1815.
Just a rough idea, if anyone wants to play with it, go ahead.