FROM THE EARLIEST days America sought to stand apart from the vanities and machinations that had corrupted monarchies in Europe. In 1853 it asked its diplomats not to wear court dress: frippery was not worthy of a serious-minded young republic. Unfortunately, at royal receptions American diplomats in dark tailcoats were sometimes confused with butlers.

Long before anyone had heard of an “ethical foreign policy”, before the revolution even, America saw itself as a New Jerusalem that would be a model for a better world. Over the course of a century or two, the monarchies and dictatorships gradually caught up. Influence abroad increasingly stemmed not just from hard power but also from legitimacy.

Thanks to symbols ranging from Hollywood to NASA, America can draw on a rich store of soft power. Its statesmen generally do set out to make the world a better place. But, as with those butler-diplomats, the message can get scrambled.

After the devastating attacks of September 11th 2001, American foreign policy lost its compass. It was right to try to foster liberty and security, by attacking al-Qaeda and seeking to prevent the proliferation of weapons of mass destruction. Yet that effort somehow ended up looking to much of the world as if America was bent on imposing violent change by means of raw power. The country is still paying the price today.

As the world’s most powerful nation, America is bound to attract some criticism. When he spoke to the UN General Assembly about the Middle East in September, Barack Obama observed wryly that America is “chastised for meddling in the region…at the same time, the United States is blamed for failing to do enough to solve the region’s problems.”

Likewise, America is criticised by Russia and others who argue that today’s anarchic militia violence in Libya proves that it was wrong to remove Muammar Qaddafi from power. Yet America would have been condemned just as roundly from other quarters if it had stood by while Qaddafi carried out his threat to slaughter thousands in Benghazi.

Sometimes, too, America has interests that unavoidably cut across the agenda or sensibilities of another country. Leaks by Edward Snowden, a security contractor, show that the National Security Agency spies more broadly and more intrusively than many people thought. He has raised genuine questions about the legal supervision of the NSA within America. His revelations have also infuriated American allies in Germany, France, Brazil and Mexico, which are not protected by the federal courts.

Some of the anger is deeply felt, not least in Germany, where the tapping of the mobile phone of the chancellor, Angela Merkel, had overtones of the Stasi. More often, though, the outrage is slightly confected. France can boast its own history of successful spying, not all of it squeaky clean. Mexico is plagued by drugs syndicates, some of which have infiltrated national politics. America’s foreign spying comes down to questions of the accountability of the NSA and a case-by-case judgment about whether the information is worth the grief if found out.

George Bush’s invasion of Iraq in 2003 was altogether different from the decisions to bomb Libya and to spy, because there was never a question of a trade-off. The removal of Saddam Hussein was meant to eradicate weapons of mass destruction, create a model democracy in the Middle East and demonstrate to rogue states that they could not defy the world’s only superpower. And yet this grand exercise in geopolitical engineering spectacularly failed to achieve its aims. Instead, Iraq was thrown into turmoil and America was weakened both militarily and morally. No other single foreign-policy decision in recent times has so harmed its standing in the world.

One flaw, says Dennis Ross of the Washington Institute for Near East Policy, was to mistake the connections between interests and values. The people around Mr Bush reasoned that, as the only superpower in a unipolar world, the United States was able to impose its values and that this would necessarily serve its interests. In the real world, however, the use of force can create regional instability. That often harms American interests.

Another error was to subordinate means to ends. So convinced was Mr Bush of the justice of his cause that he sanctioned the torture of prisoners. Separately, he provided for the indefinite internment of prisoners in Guantánamo Bay without trial. As a president bent on a moral mission, Mr Bush looked as if he thought might meant right.

A third mistake was to sweep innumerable insurgencies and jihadist movements into one worldwide war on terror. This galvanised the American public into supporting the campaigns in Afghanistan and Iraq. But, says Ms Flournoy, the former Pentagon official, it made local groups internationally relevant, helping them to gain funding and recruits.

Seizing the unipolar moment

Mr Bush’s fundamental error, though, was to misunderstand the significance of the “unipolar moment”. After the traumatic attacks of September 11th, Mr Bush’s vice-president, Dick Cheney, thought that America had to use its strength to re-establish deterrence and preserve its unrivalled power. If not, it would be asking for further attacks from terrorists, rogue states and even, some time in the future, China.

That is not how it seemed to much of the rest of world. Horrified by al-Qaeda’s assault, many countries stood behind America. But as time went on, Mr Bush’s behaviour began to look more like aggression than protection. When Mr Bush tried to impose American values through the invasion of Iraq, other countries wondered if they were safe. When he and his officials belittled international institutions like the UN and argued that the harsh treatment of prisoners was just, they feared that America would not be bound even by its own norms.

It seemed as if America had fallen into a trap that Charles de Gaulle, the French president, had pointed out 40 years earlier. The general told the American ambassador to Paris that all countries with overwhelming power mistakenly come to believe that force will solve everything.

This was Mr Obama’s inheritance. He spent much of his first term dealing with it, rebuilding relations, ending the campaign in Iraq, planning the withdrawal from Afghanistan and pursuing Osama bin Laden. One task is to persuade more countries that American primacy is helpful rather than threatening. For that, Mr Obama needs to redefine the role of values.

Foreign-policy “realists” urge that it should be minimal. Yet there is a balance to strike, because values have an essential part in establishing legitimacy. Before America led NATO to rescue Bosnia, the country burned; today its peoples are estranged but at peace. One of Mr Kissinger’s most successful acts, during the Ford years, was to sign the Helsinki accords, which became a charter for dissidents in Warsaw Pact countries. By contrast, the failure to prevent genocide in Rwanda, hardly a strategic priority for America, haunted the presidency of Bill Clinton. As a result, he later felt extra pressure to intervene elsewhere.

In his speeches Mr Obama has made a stab at setting a new balance. He starts by affirming democracy, human rights and open markets, insisting that they are not Western exports but fundamental values. He goes on to accept that these ideas cannot be imposed by force, which means that America will sometimes be accused of hypocrisy for working with undemocratic governments. But he also gives warning that some governments’ crimes will be so egregious that other nations must act. If they fail, they will be undermining the very norms and institutions that they claim to cherish.

For this approach to succeed, Mr Obama must also oversee a second reversal of Bush-era policies. Contrast Mr Bush’s unilateralism with an earlier period when the United States had enjoyed extraordinary power, between 1945 and 1950. It realised then that its hegemony over the non-Soviet world would be enhanced if it bound itself into international bodies like the UN, the IMF and the General Agreement on Tariffs and Trade, the precursor to the WTO. This sent a signal that America was committed to living by its own norms.

In the same way, Mr Obama wants to become a joiner and coalition-builder. “We want to galvanise collective action”, says Ben Rhodes, the deputy National Security Adviser, “to underpin global norms. We don’t want to do these things alone; we welcome others to be involved.” He singles out emerging powers, such as Brazil, Turkey and Indonesia, and regional groups such as ECOWAS, the Economic Community of West African States.

That might seem like wishful thinking, especially following the stalemate over Syria in the UN Security Council, in which Russia and China have protected Bashar Assad in spite of his crimes. And yet, as Bruce Jones, the American academic, points out, America has enjoyed plenty of co-operation and there is scope for even more. In 2012 China suggested a quiet dialogue with America over the chronic instability in Pakistan. Middling countries, such as Denmark and Norway, have helped broker agreements on the use of the Arctic. In Yemen, Somalia, Mali and Uganda, America or one of its closest allies have dispatched forces with the unanimous backing of the UN Security Council. Rising powers, Mr Jones argues, have growing interests in every region and subregion of the world. To maintain this network, they have to co-operate with others.

Will it work? John Podesta, Bill Clinton’s chief of staff, has observed that in a world which imposes restraints on power, America will also be obliged to restrain its own power. Presidents Truman and Roosevelt saw that this makes sense. But, as Mr Podesta argues, “you have to believe it’s a strength and sell it as a strength.” The worry is that an America convinced of its own decline is not yet capable of that.