U.S. President Barack Obama on Tuesday condemned Iran's crackdown on protesters inspired by Egypt's popular uprising and urged friends and foes across the Middle East to take heed of their peoples' aspirations for democracy.

As unrest spread in the oil-rich region, Obama drew a distinction between Iran's harsh treatment of opposition demonstrators and the Egyptian army's more restrained handling of protests that drove President Hosni Mubarak from power on Friday.

I find it ironic that you've got the Iranian regime pretending to celebrate what happened in Egypt, when in fact they have acted in direct contrast to what happened in Egypt by gunning down and beating people who were trying to express themselves peacefully, Obama said at a White House news conference.

Obama spoke four days after Mubarak handed over power to the Egyptian army following a wave of mass protest, leaving Washington facing deep uncertainty and huge challenges with repercussions for U.S. policy across the Middle East.

In words apparently directed at the region's autocratic rulers, Obama said his message was the world is changing ... if you are governing these countries, you've got to get out ahead of change, you can't be behind the curve.

But Obama still hewed to a cautious line, expressing wariness of instability that could undermine U.S. interests even as he endorsed the need for broader freedoms.

He faces the test of keeping the power shift in Cairo -- marking the end of Mubarak's 30-year authoritarian rule -- from unnerving Middle East allies like Saudi Arabia and Israel.

Obama said Egypt's new military rulers were sending the right signals about moving toward democracy, and he defended his handling of the crisis in the face of criticism he was slow to respond. We were on the right side of history, he said.

ACCUSES IRAN OF HYPOCRISY

Obama had tough words for Iran's government, accusing it of hypocrisy after it broke up an opposition rally on Monday inspired by the popular revolts in Egypt and Tunisia.

Obama's expression of solidarity with the Iranian protesters followed widespread criticism at home in 2009 for not being vocal enough during Tehran's crackdown on the opposition after a disputed presidential election.

The U.S. administration was cautious then out of fear an outright endorsement would backfire on the protesters because of strong anti-American sentiment in Iran.

My hope and expectation is that we are going to continue to see the people of Iran have the courage to be able to express their yearning for greater freedom and a more representative government, Obama said.

But Obama, who has led Western efforts to impose sanctions on Tehran over its nuclear program, insisted the United States cannot ultimately dictate what happens inside of Iran.

Iranian lawmakers on Tuesday called for the death penalty for opposition leaders they accused of fomenting unrest after a Monday rally in which security forces clashed with protesters. At least one person was killed and dozens were wounded, state media said.

Anti-government demonstrations also simmered on Tuesday in Yemen and Bahrain, two key U.S. allies, as the pro-democracy fervor that toppled Mubarak rippled across the Middle East.

Obviously, we're concerned about stability throughout the region, Obama said. He insisted that even as we uphold these universal values, we want to make sure that transitions do not degenerate into chaos and violence.

But seizing the chance to put Iran, a longtime U.S. foe, on the spot, he urged all governments in the region to deal peacefully with protests, as the Egyptian military had done.

What has been true in Egypt should be true in Iran, which is that people should be able to express their opinions and their grievances and seek a more responsive government, he said. What's been different is the Iranian government's response, which is to shoot people and beat people and arrest people.

Iran's Supreme Leader Ayatollah Ali Khamenei had described the revolts in Egypt and Tunisia as an Islamic awakening.

Western officials say they believe economic sanctions are starting to squeeze the Iranian government, and are now debating next steps following inconclusive talks in Istanbul last month. Tehran insists its nuclear program is for energy purposes, not for bomb-making.