Fars News / Reuters file Iranian President-elect Hassan Rouhani waves to reporters during a news conference in Tehran on June 17.

In a series of comments on Twitter over the past 24 hours, Iran’s new president said Iranian officials "completely and strongly condemn the use of chemical weapons in Syria," and urged the United Nations to "use all its might" to prevent more attacks.

He later slightly softened his tone, tweeting that the international community should show "prudence" in resolving the crisis in Syria.

Hassan Rouhani, who took office earlier this month, did not blame any of the players in Syria's civil war for the chemical weapons attacks, but did raise the possibility that Syrian rebels were responsible.

Rouhani’s online comments were generally more even-handed than statements made by other Iranian leaders, possibly reflecting his stated desire for improved relations with the West.

But Hooman Majd, an author and consultant to NBC News on Iranian affairs said that his tweets were his way of reflecting public sentiment in the Islamic Republic.

"This is a popularly elected president, reflecting what the population is feeling on something like this," said Majd. "He is speaking on behalf of the survivors of the chemical weapons attacks in Iran. It is not him challenging the leader (Ali Hosseini Khamenei) or condemning an ally."

The first set of tweets from Rouhani came in quick succession early Tuesday:

We completely & strongly condemn use of chemical weapons in #Syria because Islamic Republic of Iran is itself victim of chemical weapons 1/2 — Hassan Rouhani (@HassanRouhani) August 27, 2013 Iran suffered chemical weapons attacks by Iraqi forces during the 1980-1988 Iran-Iraq war 2/2 — Hassan Rouhani (@HassanRouhani) August 27, 2013

The English-speaking president was referring to Iran's experience with chemical weapons at the hands of toppled Iraqi dictator Saddam Hussein. Tens of thousands of Iranian soldiers died when Iraq used nerve and blistering agents on its troops in battles for the southern marshlands in the 1980s, during the eight-year Iran-Iraq war.

His strongest comments followed:

Iran gives notice to international community to use all its might to prevent use of chemical weapons anywhere in the world, esp. in #Syria — Hassan Rouhani (@HassanRouhani) August 27, 2013

Early Wednesday, however, he shifted to more cautious language:

As UN resumes investigations, President #Rouhani calls on intl community to show #prudence over #Syrian crisis and observe international law — Hassan Rouhani (@HassanRouhani) August 28, 2013 ’

That was followed by:

Any action on #Syrian crisis should be based on intl law, lead to more stability in region&reduce terrorism.Mid-East doesnt need another war — Hassan Rouhani (@HassanRouhani) August 28, 2013

At the same time Rouhani was tweeting his comments, other Iranian leaders were either warning about the unforeseen consequences that could arise from a U.S. strike against Syria or that it could trigger a military response against Israel.

Iran's Supreme Leader Ayatollah Ali Khamenei warned in a statement broadcast on Iranian state television that "the region is like a gunpowder store and the future cannot be predicted.”

“If (President Barack Obama) gets stuck in this trap, he will certainly leave behind bad memories of his presidency,” he added. “The intervention of America will be a disaster for the region.”

The most vitriolic claim came from Iranian legislator Mansur Haqiqatpur, who was quoted by the Fars news agency as saying, “In case of a U.S. military strike against Syria, the flames of outrage of the region’s revolutionaries will point toward the Zionist regime,” as reported by the New York Times.

At the same time, Iran's new foreign minister, Mohammed Javad Zarif, suggested the Syrian rebels may have gained access to nerve agents and carried out the attack on their own supporters. He urged that possibility be investigated.

Related story

Iran's Khamenei warns US intervention in Syria would be 'disaster' for Middle East

The mixed messages are not unusual, said Majd, the NBC News consultant.

Government institutions in Iran "rarely speak with one voice," particulary at time of political transition, he said. He also noted that the regime itself "is much more guarded in its actions" than is reflected in the rhetoric of its leaders, whether "it's a statement that the U.S. might like, like this, or those made by Ahmadinejad on Israel, which the U.S. might not like."

Rouhani has said that he is hoping for better relations with the West, particularly the United States, and has appointed two U.S.-educated diplomats to the positions of foreign minister and chief nuclear negotiator.

More from NBC News Investigations:

Follow NBC News Investigations on Twitter and Facebook