WASHINGTON — Rioters storming U.S. embassy gates. American flags torn down and set ablaze. The latest scenes exploding across TV screens have particular resonance for those who remember the hostage crisis in Iran that helped cost Jimmy Carter his presidency and bring Ronald Reagan to power.

And they are making at least some Democrats nervous about the potential effect on the election this November.

But whether the overseas contagion will affect the election depends at least in part on how long it lasts and how seriously events spiral out of control. Most crucial of all, analysts say, will be the ultimate toll in American lives and on national pride.

The wave of violence in the Mideast comes at a critical juncture in the U.S. presidential contest. Polling conducted after the recent national party conventions seemed to indicate that President Barack Obama might have been opening a lead in what has been, for months, a tight race with Mitt Romney.

“When you are ahead, you hate to have anything stir the pot,” said Democratic strategist Paul Maslin. “Now you have a wild card in here.”

But there are also many differences between today and that pre-9/11 era.

“Iran was a shock 30 years ago. We’re not shocked anymore by scenes like that out of the Middle East,” said Maslin, a pollster in the Carter re-election campaign.

For the first time in a long while, Obama and the Democrats have a clear advantage on national security issues. That’s in large part a result of Obama’s successful pursuit of al-Qaida mastermind Osama bin Laden.

Surveys taken for Resurgent Republic, a conservative Republican organization, found that voters feel that they are better off than they were four years ago on only one measure — safety from terrorists (other dimensions tested were the economy, the government’s fiscal situation and America’s overall standing in the world).

“It’s pretty difficult to paint the guy who got Osama bin Laden as somehow weak and vacillating when it comes to dealing with our enemies,” said Whit Ayres, who conducted the polling.

The Republican strategist said that the crisis unfolding overseas “obviously doesn’t make Americans happy. The question is, will it supplant the dominant issues of the economy, jobs, spending and debt?”

Romney aides are trying to make the Carter connection for voters, echoing a theme that had been simmering in the background of their campaign for more than a year, that Obama was destined to become the next one-term Democratic president.

“For the first time since Jimmy Carter, we’ve had an American ambassador assassinated,” Richard Williamson, a Romney foreign policy adviser and one-time Reagan White House political aide, said to The Washington Post last week.

But for all of Carter’s difficulties with the hostage crisis — a failed rescue mission in April of the election year left eight U.S. servicemen dead — it took many months for the crisis to undermine his standing with voters. The public initially rallied behind Carter, helping him crush a challenge from Sen. Edward Kennedy in the Democratic primaries.

And Romney has yet to gain credibility on foreign policy issues. He was criticized by some Republicans for his response to the attack on the U.S. Consulate in Libya, which they said looked crassly political.

A series of gaffes on an overseas trip during the summer also underscored his lack of foreign policy experience.

Obama, meanwhile, has intelligence information not available to his challenger, and the authority to respond to overseas threats. He vowed again, at a ceremony Friday for those killed in Benghazi, Libya, that “we will bring to justice those who took them from us” in the consulate attack.

If relative calm is not restored in the Middle East, however, Romney’s argument that Obama’s policies aren’t working could start to sink in with voters. The Republican would be positioning himself as tougher and more resolute than the incumbent.

Democratic strategist Bill Carrick said Romney may have trouble selling his more muscular policy, particularly with independents and even some Republican voters, given their sentiments about the George W. Bush years.

“I don’t think the neoconservative version of American foreign policy is going to prevail, given the incredible experience the American people have had with Iraq and Afghanistan and the length of those wars and how many people have been killed and damaged and what it has done to our own economy,” Carrick said. “I don’t think people are ready for that.”