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 ouster. Some said it was a potentially positive step for democracy - a sign, as President 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 Sanders' rivals paid little attention to the incident in a faraway place. But for 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 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. Trump has already upended the world order with an "America First" approach that tests Western alliances, and Sanders would deliver another jolt - echoing some of Trump's criticisms of military actions and free trade but realigning the country's priorities even more thoroughly.

Beyond his objection to Morales' removal, Sanders has pointedly declined to label Venezuelan President Nicolás Maduro a dictator. He called Israeli Prime Minister Benjamin Netanyahu a "racist", and has campaigned with Representatives Rashida Tlaib, Democrat-Michigan, and Ilhan Omar, Democrat-Minnesota, 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".

ANDREW HARNIK/AP If Democratic presidential candidate Senator Bernie Sanders was elected president it would mean another jolt to America's role in the world.

And as 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 Sanders has put much more emphasis on domestic policies than global ones. "It hasn't been his strong suit," Senator Richard Durbin, Democrat-Illinois, said of Sanders' foreign policy.

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, Sanders' positions are often more nuanced than he's given credit for - he has criticised Morales and Maduro, for example, even while questioning the wisdom of removing them.

AP While Sanders and his supporters say he's been right on foreign policy more than the experts, he has previously appeared unprepared on the subject.

"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," 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."

Sanders' campaign declined to make him available for an interview. In a statement, 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".

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. Sanders was at odds with many in the party last year, for example, when he refused to call Maduro a dictator, even as he made critical comments about the authoritarian socialist leader.

His comments about Morales, whose success lifting Bolivians into the middle class made him an iconic figure among socialists, also stood out. At a Univision forum, Sanders praised 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 toward a man whom many viewed as increasingly authoritarian.

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.

PATRICK SEMANSKY/AP While Sanders' unorthodox views make some Democrats nervous, the most pointed hostility comes from Republicans.

When he ran for president four years ago, 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, 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 Sanders' world as a potential future national security adviser - Duss rose from blogging about policy to helming the Foundation for Middle East Peace.

In the years after his loss to Clinton, 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."

Cheryl Senter Those who have worked with Sanders on foreign policy have said he is methodical and inquisitive.

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, Sanders has increasingly clashed with Biden, who touts his extensive foreign policy experience in the Senate and Obama administration.

David Lammy, a member of British Parliament who has gotten to know Sanders in recent years, noted that Sanders' views would fit more comfortably in a typical European center-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," Lammy said.

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

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

Standing next to him in an elevator in the Capitol was Senator Rick Scott, Republican-Florida, who chuckled and interjected: "Does he have a foreign policy?"

Yet this is a time of foreign policy upheaval in both parties. 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, Democrat-Hawaii, and Senator Rand Paul, Republican-Kentucky.

That has given 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 Trump to issue his second veto.

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

Other alliances have been more controversial. Omar and Tlaib, who have endorsed Sanders for president, strongly support the Boycott, Divestment and Sanctions movement to pressure Israel over its policies toward 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, Democrat-Maryland, formerly the top Democrat on the Senate Foreign Relations Committee.

Sanders himself does not support the BDS movement. But he has been a vocal critic of 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, 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 AFL-CIO and Senator Elizabeth Warren, Democrat-Massachusetts, among others on the left.

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

Trade politics also divided Sanders and President Barack Obama. "He may have more differences with Obama on foreign policy than Trump, is the great irony," said John Cavanagh, who has known 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 Sanders has his stark differences with Trump as well. The senator from Vermont was a lonely voice opposing the most recent defence spending bill. And Sanders favours international diplomacy to tackle big issues such as the Paris climate accord.

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

News of the airstrike came late January 2, after Sanders had spent the day campaigning in Iowa. Inside a restaurant at the Doubletree Hotel in Cedar Rapids, Sanders huddled with aides including campaign manager Faiz Shakir and his deputy, Ari Rabin-Havt, according to a person with knowledge of the situation. 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 Trump for ordering Soleimani's killing.

Those who have worked with Sanders on foreign policy describe him as methodical and inquisitive. Suzanne DiMaggio, a senior fellow at the Carnegie Endowment who is advising Sanders on Iran, recalled him asking specific questions about the consequences of 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?" DiMaggio said.

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

A more vivid memory for Rhodes was how 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 Rhodes, who has offered informal advice to Sanders and other candidates. "And Bernie measured that by not having to attend as many funerals in Vermont."