When Bolivia's leftist president was pressured to resign by his country's military after an audit found signs of a tainted election two months ago, many American leaders showed little interest in condemning the ousting. Some said it was a potentially positive step for democracy – a sign, as Donald Trump put it, that "the will of the people will always prevail."

A sharply different response came from senator Bernie Sanders, who immediately condemned "what appears to be a coup." The ousted leader, Evo Morales, who had challenged term limits to remain in power, later thanked the senator from Vermont and Democratic presidential candidate, referring to him affectionately as "brother."

Most of Mr Sanders' rivals paid little attention to the incident in a faraway place. But for Mr Sanders, the episode offered a glimpse into an unorthodox foreign policy worldview – anchored by a passionate opposition to US military interventions – that has been overshadowed by his famously liberal domestic policy agenda.

With the Iran crisis thrusting foreign affairs to the forefront of the campaign, just as Mr Sanders rises in early state polls, Democrats who previously waved off the senator's views as fringe ideas now must contemplate the possibility of a democratic socialist becoming commander in chief of the United States. Mr Trump has already upended the world order with an "America First" approach that tests Western alliances, and Mr Sanders would deliver another jolt – echoing some of Mr Trump's criticisms of military actions and free trade but realigning the country's priorities even more thoroughly.

Beyond his objection to Mr Morales' removal, Mr Sanders has pointedly declined to label Venezuelan president Nicolas Maduro a dictator. He called Israeli prime minister Benjamin Netanyahu a "racist," and has campaigned with representatives Rashida Tlaib and Ilhan Omar vocal supporters of a controversial Israel boycott movement. He said China has done more to address extreme poverty "than any country in the history of civilisation."

US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Show all 35 1 /35 US airstrike kills Iran's Qassem Soleimani: Fallout in pictures US airstrike kills Iran's Qassem Soleimani: Fallout in pictures This photo released by the Iraqi Prime Minister Press Office shows a burning vehicle at the Baghdad International Airport following an airstrike in Baghdad, Iraq, early Friday 3 January AP US airstrike kills Iran's Qassem Soleimani: Fallout in pictures The wreckage of the car in which general Soleimani was travelling when a targeted US airstrike struck outside Baghdad International Airport on 3 January Ahmad Al Mukhtar via Reuters US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Demonstrators burn the US and British flags during a protest in Tehran after general Soleimani was killed in a targeted airstrike by American forces Reuters US airstrike kills Iran's Qassem Soleimani: Fallout in pictures A burning vehicle at the Baghdad International Airport following an airstrike. The Pentagon said Thursday that the US military has killed general Qassem Soleimani, the head of Iran's elite Quds Force, at the direction of Donald Trump AP US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Protesters burn Israeli and US flags as thousands of Iranians take to the streets to mourn the death of general Soleimani at the hands of America EPA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Supporters of Donald Trump pray at an 'Evangelicals for Trump' campaign event held on the day following the killing of general Soleimani. At the event, the president praised the "flawless strike that eliminated the terrorist ringleader" AFP via Getty US airstrike kills Iran's Qassem Soleimani: Fallout in pictures A huge procession of mourners gather in Baghdad for the funeral of general Soleimani on 4 January AP US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Thousands of Iranians take to the streets to mourn the death of Soleimani during an anti-US demonstration to condemn the killing of Soleimani, after Friday prayers in Tehran, Iran EPA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Iraqis perform a mourning prayer for slain major general Qasem Soleimani of the Iranian Revolutionary Guards at the Great Mosque of Kufa AFP via Getty US airstrike kills Iran's Qassem Soleimani: Fallout in pictures A billboard reading 'Death to America and Israel', installed by Iran-backed shiite armed groups at a street in Jadriyah district in Baghdad, Iraq EPA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures A handout picture provided by the office of Iran's supreme leader Ayatollah Ali Khamenei shows him visiting the family of Soleiman KHAMENEI.IR/AFP via Getty US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Thousands of Iranians take to the streets in Tehran EPA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Pakistani Shiite Muslims burn a mock of a US flag as they hold pictures of General Qasem Soleimani during a protest against the USA, outside the US Consulate in Lahore, Pakistan EPA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Iran's Ambassador to Lebanon Mohammed Jalal Feiruznia, looks to a portrait of Soleimani, as he receives condolences at the Iranian embassy, in Beirut, Lebanon AP US airstrike kills Iran's Qassem Soleimani: Fallout in pictures People make their way on the street while a screen on the wall of a cinema shows a portrait Soleimani in Tehran AP US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Aziz Asmar, one of two Syrian painters who completed a mural following the killing of Iranian Revolutionary Guards commander Qasem Soleimani poses next to his creation in the rebel-held Syrian town of Dana in the northwestern province of Idlib AFP via Getty US airstrike kills Iran's Qassem Soleimani: Fallout in pictures A demonstration in Tehran AFP via Getty US airstrike kills Iran's Qassem Soleimani: Fallout in pictures An anti-US demonstration to condemn the killing of Soleimani, after Friday prayers in Tehran EPA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Mujtaba al-Husseini, the representative of Iran's supreme leader Ayatollah Ali Khamenei, delivers a speech in the holy shrine city of Najaf AFP via Getty US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Pakistani Shiite Muslims burn a mock of a US and Israeli flags as they hold pictures of General Qasem Soleimani during a protest against the USA, outside the US Consulate in Lahore, Pakistan EPA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Protesters demonstrate in Tehran AP US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Pakistani Shi'ite Muslims hold pictures of General Qasem Soleimani during a protest against the USA, in Peshawar, Pakistan EPA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Protesters, holding a photograph of the leader of the People's Mujahedin of Iran Massoud Rajavi, outside Downing Street in London PA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Protesters burn a US flag in Tehran AP US airstrike kills Iran's Qassem Soleimani: Fallout in pictures A Syrian man offers sweets to children to mark the killing AFP via Getty US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Iranian worshippers attend a mourning prayer for Soleimani in Iran's capital Tehran AFP via Getty US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Kashmiri Shiite Muslims shout anti American and anti Israel slogans during a protest AP US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Iranian worshipers chant slogans during Friday prayers Reuters US airstrike kills Iran's Qassem Soleimani: Fallout in pictures A protest against the USA, in Islamabad, Pakistan EPA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Iranians burn a US flag in Tehran EPA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Supporters of the National Council of Resistance of Iran in Germany (NWRI) protest outside Iran's embassy in Berlin, Germany Reuters US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Supporters of the National Council of Resistance of Iran in Germany (NWRI) protest outside Iran's embassy in Berlin Reuters US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Iranian worshippers in Tehran AFP via Getty US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Vehicles of the United Nations Interim Forces in Lebanon (UNIFIL) patrol a road in the southern Lebanese town of Kfar Kila near the border with Israel. Following morning's killing of Major General Qasem Soleimani, Lebanon's Iran-backed Hezbollah movement called for the missile strike by Israel's closest ally, to be avenged AFP via Getty US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Iranian women take to the streets in Tehran EPA

And as Mr Sanders has noted repeatedly in recent days, he opposed the 2003 invasion of Iraq that most US leaders, including former vice president Joe Biden, supported, advancing an argument that he is the most unwavering antiwar candidate in the race.

"I think it would a be fundamental shift, assuming his principles hold in the transition from campaigning to governing," said Aaron David Miller, a former adviser to six secretaries of state and now a senior fellow at the Carnegie Endowment for International Peace. "You've had a consensus in this country on certain principles. Joe Biden represents that consensus. And to a degree, Obama as well."

Even some Democrats note that Mr Sanders has put much more emphasis on domestic policies than global ones. "It hasn't been his strong suit," senator Richard Durbin said of Mr Sanders' foreign policy.

Mr Sanders and his supporters say he's been right on foreign policy far more than the supposed experts, and that the establishment is responsible for a series of misguided military adventures. Besides, they say, Mr Sanders' positions are often more nuanced than he's given credit for – he has criticised Mr Morales and Mr Maduro, for example, even while questioning the wisdom of removing them.

"What were the two major foreign policy blunders in our lifetimes? Help me out here. What were they? Vietnam was one, and Iraq was the other," Mr Sanders said Saturday at a town hall in Newton, Iowa. "I marched against the war in Vietnam. I was a kid. As a United States congressman in 2002, 2003, I helped lead the effort to prevent us from invading Iraq."

Mr Sanders' campaign declined to make him available for an interview. In a statement, Mr Sanders' national policy director Josh Orton said: "Washington's foreign policy establishment has been consistently wrong," and that a Sanders administration would "begin to repair the damage done by Trump."

Mr Sanders, 78, was strongly influenced by the Reagan-era US interventions in Latin America, which appalled many liberals. Those years also influenced his broader approach to the region, which stands apart from many Democrats. Mr Sanders was at odds with many in the party last year, for example, when he refused to call Mr Maduro a dictator, even as he made critical comments about the authoritarian socialist leader.

His comments about Mr Morales, whose success lifting Bolivians into the middle class made him an iconic figure among socialists, also stood out. At a Univision forum, Mr Sanders praised Mr Morales for addressing poverty and empowering indigenous people. He added that it was fair to question whether he should have stayed in power so long – almost 14 years – but it was a far less critical approach than other Democrats took towards a man whom many viewed as increasingly authoritarian.

Mr Sanders has been accused by members of both parties of not being tough enough on repressive socialist regimes. "He's not going to pretend we face remotely equivalent threats from left-wing authoritarianism than from right-wing authoritarianism," said a senior Sanders aide, speaking on the condition of anonymity to be candid.

When he ran for president four years ago, Mr Sanders often appeared unprepared for a rigorous foreign policy debate. Facing opponent Hillary Clinton, a former secretary of state, he often sidestepped questions about specific global challenges.

Following his loss, Mr Sanders sought to shore up his foreign policy credentials. After the 2016 election, he hired Matt Duss, who has helped the candidate with his foreign policy chops. Now his top foreign policy hand – and seen inside Mr Sanders' world as a potential future national security adviser –Mr Duss rose from blogging about policy to helming the Foundation for Middle East Peace.

In the years after his loss to Ms Clinton, Mr Sanders delivered some lengthy speeches on foreign policy, including one at Westminster College in Missouri, where Winston Churchill gave his famous "Iron Curtain" address.

That 2017 Sanders speech encapsulated much of his thinking on world affairs, people close to him said. In it, he tethered his foreign policy vision to his populist domestic agenda, declaring, "We cannot convincingly promote democracy abroad if we do not live it vigorously here at home."

Mr Sanders argued that the events of the past two decades have discredited the notion that the US should use its military might to shape the world to its liking. He decried US interference in Iran and Chile in the 20th century. He underlined the need for alliances to confront adversaries such as North Korea. On a smaller scale, he touted the value of partnering with a sister city in Russia when he was mayor of Burlington, Vermont.

Many Democrats remain unimpressed. On the campaign trail, Mr Sanders has increasingly clashed with Mr Biden, who touts his extensive foreign policy experience in the Senate and Obama administration.

Mr Sanders sat with Evo Morales at a conference the economy and social justice at the Vatican in 2016 (AP)

David Lammy, the British MP, who has gotten to know Mr Sanders in recent years, noted that Sanders' views would fit more comfortably in a typical European centre-left party. "Whether he were in Germany or France or the UK, of course, Bernie, his politics would be very familiar and probably quite mainstream," Mr Lammy said.

He added, "Clearly, in the US context, it has been a slightly different experience."

While Mr Sanders' unorthodox views make some Democrats nervous, the most pointed hostility comes from Republicans. Asked what he thinks of Mr Sanders' foreign policy platform, senator Thom Tillis said, "A disaster."

Standing next to him in an elevator in the Capitol Building was senator Rick Scott who chuckled and interjected, "Does he have a foreign policy?"

Yet this is a time of foreign policy upheaval in both parties. Mr Trump himself has upended decades of Republican thinking, praising figures such as North Korean leader Kim Jong Un while questioning the role of Nato. A populist non-interventionism is surging in both parties, championed by figures such as representative Tulsi Gabbard and senator Rand Paul.

That has given Mr Sanders a sometimes surprising array of foreign policy partners on Capitol Hill. He teamed up with senator Mike Lee, a conservative Republican from Utah, on a measure to end US support for the Saudi-led military campaign in Yemen. Their legislation passed the Senate and forced Mr Trump to issue his second veto.

On Saturday, Mr Lee signed onto Mr Sanders' bill to prevent Mr Trump from deploying funds for military action against Iran without congressional approval.

Other alliances have been more controversial. Representatives Ilhan Omar and Rashida Tlaib, who have endorsed Mr Sanders for president, strongly support the Boycott, Divestment and Sanctions (BDS) movement to pressure Israel over its policies towards Palestinians.

Many Democrats and Republicans, including some who have criticised Israeli policies, object to the BDS movement as going too far. "To me, BDS has no place," said senator Ben Cardin, formerly the top Democrat on the Senate Foreign Relations Committee.

Mr Sanders himself does not support the BDS movement. But he has been a vocal critic of Mr Netanyahu, and he has said he is willing to make foreign aid to Israel contingent on fostering more peaceful relations with Palestinians, a condition many Democrats and Republicans are unwilling to impose.

When it comes to international trade, Mr Sanders opposes an emerging US deal with Mexico and Canada, arguing that it does not go far enough in protecting American jobs. The deal has the support of the union AFL-CIO and Elizabeth Warren among others on the left.

To some moderate Democrats, including senator Jon Tester of Montana, Mr Sanders' message at times can resemble the current president's promises to avoid needless wars. "Kind of like Trump?" Mr Tester mused in a brief interview at the Capitol. Mr Sanders' identification as a democratic socialist is "something he has to overcome" in his pitch to be commander in chief, Mr Tester added.

Trade politics also divided Mr Sanders and Barack Obama. "He may have more differences with Obama on foreign policy than Trump, is the great irony," said John Cavanagh, who has known Mr Sanders since 1991 and directs the Institute for Policy Studies, a liberal think tank. "Both he and Trump can sit down with workers in the Midwest. It's just that one does it in a racist and xenophobic way."

But Mr Sanders has his stark differences with Mr Trump as well. The senator from Vermont was a lonely voice opposing the most recent defence spending bill. And Mr Sanders favours international diplomacy to tackle big issues such as the Paris climate accord.

Until recently, Mr Sanders' proposals have been overshadowed by his sweeping domestic agenda. But the US killing of Iranian military commander Qassem Soleimani prompted Mr Sanders to amplify the linchpin of his foreign agenda: his long-standing opposition to US intervention abroad.

News of the airstrike came late 2 January, after Mr Sanders had spent the day campaigning in Iowa. Inside a restaurant at the Doubletree Hotel in Cedar Rapids, Mr Sanders huddled with aides including campaign manager Faiz Shakir and his deputy, Ari Rabin-Havt, according to a person with knowledge of the situation. Mr Duss, the foreign policy adviser, joined by phone. Together, they crafted a statement calling the killing an "assassination" and drew a connection to the instability caused by the Iraq War.

"It gives me no pleasure to tell you at this moment we face a similar crossroads fraught with danger," he said the next day during a town hall meeting at the National Motorcycle Museum in Anamosa, Iowa, delivering a speech he wrote and then revised on the drive from the hotel, according to the aide with knowledge of the situation.

For some at the town hall, his aversion to military conflict resonated. "We've been through this in the past," said Thomas Wiand, 51. "We went through unnecessary wars continually."

Others were more cautious. "Sometimes you have to go and do what needs to be done to correct the situation," said Craig Bruxvoort, 62, a grain farmer who applauded Mr Trump for ordering general Soleimani's killing.

Those who have worked with Mr Sanders on foreign policy describe him as methodical and inquisitive. Suzanne DiMaggio, a senior fellow at the Carnegie Endowment who is advising Mr Sanders on Iran, recalled him asking specific questions about the consequences of general Soleimani's killing.

"A lot of the questions focused on the internal political dynamics in Iran: What are the likely scenarios that will now emerge? How will it affect those who are moderates in Iran?" Ms DiMaggio said.

Ben Rhodes, who served as deputy national security adviser under Mr Obama, remembered briefing Mr Sanders on the Iran nuclear deal for about an hour, as the senator fired questions his way.

A more vivid memory for Mr Rhodes was how Mr Sanders was affected by talking to veterans and family members of soldiers killed in combat.

"I remember him telling me once, he said, 'Obama doesn't get enough credit for how many troops Obama took out from Afghanistan,'" said Mr Rhodes, who has offered informal advice to Mr Sanders and other candidates. "And Bernie measured that by not having to attend as many funerals in Vermont."