TEHRAN — Antigovernment protests roiled Iran on Tuesday, as the death toll rose to 21 and the nation’s supreme leader blamed foreign enemies for the unrest. But the protests that have spread to dozens of Iranian cities in the past six days were set off by miscalculations in a long-simmering power struggle between hard-liners and reformers.

By Tuesday, Iran’s leaders could no longer ignore the demonstrations and felt compelled to respond publicly. Ayatollah Ali Khamenei, the supreme leader, blamed outside “enemies” but did not specify whom. President Hassan Rouhani, a moderate, appealed for calm while saying the protesters had a right to be heard.

But the anger behind the protests was directed against the entire political establishment.

While the protests that swept Iran in 2009 were led by the urban middle class, these protests have been largely driven by disaffected young people in rural areas, towns and small cities who have seized an opening to vent their frustrations with a political elite they say has hijacked the economy to serve its own interests.

Unemployment for young people — half the population — runs at 40 percent, analysts believe. Meanwhile, Iran has spent billions of dollars abroad in recent years to extend its influence in Iraq, Syria and Lebanon.