The White House on Saturday congratulated Iranians for their “courage” after moderate candidate Hassan Rouhani was elected president of Iran in an upset.

The U.S. administration said it hopes the election will mean the new government will “heed the will” of the people and held out hope that a solution to the standoff over Iran's alleged nuclear weapons program can be found.

“We respect the vote of the Iranian people and congratulate them for their participation in the political process, and their courage in making their voices heard,” the Obama administration said.

“It is our hope that the Iranian government will heed the will of the Iranian people and make responsible choices that create a better future for all Iranians. The United States remains ready to engage the Iranian government directly in order to reach a diplomatic solution that will fully address the international community’s concerns about Iran’s nuclear program,” it added.

Rouhani won more than 50 percent of the vote on the first ballot and his victory has been given the blessing of Iran's religious leaders. Of the eight men allowed by Iran's religious leaders to run for the presidency, Rouhani was seen as the most friendly toward the West and most likely to seek greater personal freedoms in the theocratic state.

The Fars News Agency reported Saturday that Iranian Interior Minister Mostafa Mohammad Najjar announced Rouhani won 18,613,329 votes, accounting for 52.49% of the votes cast in the election, while his rival, Mohammad Qalibaf, got only 6,077,292 votes. The candidate closest to the religious ayatollahs, Saeed Jalili, came in third with 4,168,946 votes.

The election was blessed by Supreme Leader Ali Khamenei, who holds final sway in the Islamic republic.

The Obama administration has come under criticism for failing to give adequate support to the 2009 attempted “green revolution” in Iran. Protests against the disputed reelection of hardliner Mahmoud Ahmadinejad fizzled by 2010.

The White House noted that restrictions on full democracy continue in Iran.

“Yesterday’s election took place against the backdrop of a lack of transparency, censorship of the media, Internet, and text messages, and an intimidating security environment that limited freedom of expression and assembly. However, despite these government obstacles and limitations, the Iranian people were determined to act to shape their future,” it said.

"We admire the courage of the Iranian people who went to the polls and made their voices heard in a rigidly controlled environment that sought to limit freedom of expression and assembly," Secretary of State John KerryJohn KerryA presidential candidate pledge can right the wrongs of an infamous day Equilibrium/Sustainability — Dam failures cap a year of disasters Four environmental fights to watch in 2022 MORE said. "We remain concerned about the lack of transparency in the electoral process, and the attempts to censor members of the media, the internet, and text messages. Despite these challenges, however, the Iranian people have clearly expressed their desire for a new and better future.

"President-elect Rouhani pledged repeatedly during his campaign to restore and expand freedoms for all Iranians. In the months ahead, he has the opportunity to keep his promises to the Iranian people."

--This report was originally published at 3:12 p.m. and last updated at 7:15 p.m.