Amid a global exchange of greetings and good wishes to mark Rosh Hashanah, the Jewish new year, which began at sunset on Wednesday, there was one from a particularly surprising quarter.

Iran's president, Hassan Rouhani, tweeted: "As the sun is about to set here in #Tehran I wish all Jews, especially Iranian Jews, a blessed Rosh Hashanah." A picture of an Iranian Jew praying at a synagogue in Tehran accompanied the tweet.

According to a 2012 census, there are fewer than 9,000 Jews among Iran's population of about 75 million.

The message from Rouhani was unexpected in Israel, which has identified Iran as a huge threat to its security. It says the regime is developing a nuclear weapons programme that could be used to annihilate the Jewish state.

Rouhani, who was elected in June, has pledged to tone down the "hate rhetoric" used by his predecessor Mahmoud Ahmadinejad.

Barack Obama, also sent new year greetings to Jews around the world, wishing them "shana tova" from the Great Synagogue in Stockholm during a stopover en route to the G20 summit in St Petersburg.

Other wellwishers included the British prime minister, David Cameron, who sent "best wishes to Jewish communities in the UK and around the world observing the high holy days of Rosh Hashanah and Yom Kippur".

His message continued: "At this important time for the Jewish faith let us join you in praying for a new year that will achieve progress towards a lasting peace for Israel and the Middle East."

Rosh Hashanah marks the start of the year 5774 in the Jewish calendar and about a month of religious holidays. Yom Kippur, the solemn day of atonement and fasting for Jews, begins at sunset next Friday. It is followed by Sukkot, or the Feast of the Tabernacles, an eight-day holiday in which observant Jews take meals in a sukkah, an outdoor structure traditionally covered in palm fronds.