WASHINGTON — In October 1985, a few months after Bernie Sanders traveled to Nicaragua to celebrate the sixth anniversary of that country's socialist revolution, the Soviet-backed government suspended the civil liberties of its citizens, including the rights to free speech, free assembly and labor strikes.

A few days later, Sanders, then the socialist mayor of Burlington, Vermont, received a pointed letter from a constituent. How, the letter-writer wanted to know, could Sanders continue to embrace a "another in a long line of dictatorships, whose only true concern is its length of stay in power"?

In a written reply, Sanders — who had praised Nicaragua's leaders upon his return from the trip — made no apologies. The Nicaraguan government was fighting a "brutal war" funded by the United States, he wrote, which made the situation "complex." Didn't the U.S. government, Sanders wrote, intern Japanese Americans during World War II? Didn't Lincoln curtail basic rights during the Civil War?

Thirty-five years later, Sanders is leading in national polls to become President Donald Trump's Democratic opponent in the 2020 election. Sanders has staked out positions that are clearly to the left of the rest of the field on trade, troop deployments and military action.

Both Republicans and Democrats are already using the c-word to blunt his appeal. In Wednesday night's Democratic debate, Mike Bloomberg described Sanders stance on wealth as "communist." Trump, meanwhile, has already called Sanders a Communist.

If Sanders wins the nomination, some Democrats worry that Trump and the Republicans will hammer him on long-buried words in defense of repressive governments in Nicaragua, Cuba and the Soviet Union.

Other critics argue that Sanders' record raises questions about his foreign policy judgment, and whether, after decades of denouncing America's use of force, he would continue the aggressive counterterrorism policies embraced by both parties since the 9/11 attacks. His aides have already suggested to NBC News that the number of targeted killings of terror suspects would fall if he were president.

The current occupant of the White House has also been criticized for his public statements about autocrats, though they are strong men of a different stripe. Opponents say Trump has fawned over Russian President Vladimir Putin and the leaders of Turkey and the Philippines. Political analysts say that issue could present a potent line of attack against Trump in the fall campaign — unless Sanders is the nominee.

"Bernie Sanders is not a Democrat," said Steve Schmidt, a Republican political consultant who ran Sen. John McCain's 2008 presidential campaign and opposes Trump. "He is a socialist, and he supported communist revolutionaries all over the Western hemisphere in the 1980s at the height of the Cold War. These positions are antithetical to the values of the country, and certainly explains why the Trump campaign is so enthusiastic about Bernie Sanders as an opponent."

The Sanders campaign declined a request by NBC News to comment on his past statements about leftist governments.

'Free health care, free education, free housing'

Much about Sanders' stances on Soviet-backed U.S. adversaries has previously been reported, but political experts say the story remains unknown to most American voters. Key episodes include:

In 1972, Sanders told junior high school students in Vermont that U.S. policy in Vietnam was "almost as bad as what Hitler did," according to The Rutland Daily Herald.

On his Nicaragua visit in 1985 Sanders sat down with leader Daniel Ortega, whom he later called "a very impressive guy." At the time, human rights activists had documented serious abuses by Ortega's government.

On a trip to the Soviet Union in 1988, Sanders criticized American foreign policy to such an extent that one of the Republicans on the trip rose to rebut him and then stormed out of the room, he told NBC News.

In 1989, Sanders visited communist Cuba and lauded the country's "free health care, free education, free housing," while dismissing the government's holding of political prisoners by saying Cuba was not a "perfect society," according to The Free Press of Burlington.

Since he became a presidential candidate, Sanders has downplayed his affinity for revolutionary movements — but he hasn't repudiated anything he did or said. Running against Hillary Clinton in 2016, he sought to shift the focus away from Latin America. "When I talk about democratic socialism, I'm not looking at Venezuela. I'm not looking at Cuba," he said. "I'm looking at countries like Denmark and Sweden."

But skepticism of American power has been a hallmark of his views on foreign policy. He has generally opposed American military action, with the exception of the 1999 bombing of Kosovo, framed as an effort to prevent a genocide. Though Sanders voted to authorize military force against al Qaeda and the Taliban after 9/11, he now says that vote was a mistake and urges a repeal of that law.

He continues to hold views about Latin America that diverge from those of many mainstream Democrats.

Last year, pressed at a televised town hall by CNN's Wolf Blitzer, Sanders refused to call Venezuela's leader, Nicholás Maduro, a dictator. He has declined to recognize opposition leader Juan Guaidó as Venezuela's legitimate leader, as the U.S. and most of its allies have done. He denounced what he called a "coup" against Bolivia's leftist president, Evo Morales, despite findings by independent groups that Morales tried to steal an election.

"It was out of the mainstream back then for Democrats, and it's certainly out of the mainstream these days, too," said Brian Katulis, a Democratic foreign policy expert at the Center for American Progress. "It's just an outlier."

Other experts say Sanders' skepticism of U.S. military power is increasingly popular among an electorate, including some Trump voters, that has grown suspicious of costly American deployments in open-ended Middle East entanglements.

"The bigger picture context is Bernie has a critique of U.S. foreign policy that's long been well established and that by and large fits with the public's critiques of U.S. foreign policy," said Steven Miles, executive director of Win Without War, a nonpartisan progressive foreign policy group.

Sanders has represented Vermont in Congress as a self-identified "Democratic Socialist" since 1991. First Vermont's sole House member, he was elected to the Senate in 2006. Although he caucuses and votes with Democrats in Congress and is running for president as a Democrat, he has run in all of his races for Congress as an independent, sometimes against Democratic opponents. He has already filed to run for re-election to the Senate in 2024 as an independent.

Since he began representing the state, as opposed to the liberal enclave of Burlington, he has embraced a more conventional, if left of center, foreign policy.

He was among a majority of House Democratic caucus members to vote against authorizing the Persian Gulf War in 1991, and was one of 126 Democratic caucus members who voted against the authorization for the war in Iraq. He voted in 2001 to authorize the war in Afghanistan, but has since called that vote a mistake.

In 2015, he told Chuck Todd of NBC's "Meet the Press" that he would continue to use drones to kill high-value terrorists. But Sanders' world view is grounded in the belief that the U.S. has relied too often on military force.