* Reformist-backed cleric far ahead of nearest conservative
* Most ballots in presidential election not yet counted
* Khamenei: whatever result, vote upholds Islamic Republic
* Ruling elite keen to see no repeat of 2009 unrest
Moderate cleric Hassan Rohani soared to a huge lead over conservative rivals in preliminary vote counting on Saturday, suggesting he may be able to pull off a surprise outright victory in Iran's presidential election.
The outcome is unlikely to radically alter relations between Iran and the world or lead to a shift in the Islamic Republic's policy on its disputed nuclear programme - security issues that are decided by Supreme Leader Ayatollah Ali Khamenei.
But the president does have an important voice in decision-making in the Shi'ite Muslim country of 75 million and could bring a change from the confrontational style of President Mahmoud Ahmadinejad, who was constitutionally barred from seeking a third consecutive term.
The big lead achieved by Rohani pointed to a latent but major reservoir of pro-reform sentiment whereby many seized the chance to cut the ruling elite down to size over Iran's economic woes, international isolation and crackdowns on personal freedoms despite curbs on candidate choice and campaigning.
If he wins, Rohani, a moderate who is a former chief nuclear negotiator known for his conciliatory approach, has indicated he would promote foreign policy based on "constructive interaction with the world" and enact a "civil rights charter" at home.
In an apparent attempt to signal political continuity, Khamenei said on Saturday that whatever the result of Friday's election, it would be a vote of confidence in the 34-year-old Islamic Republic.
"A vote for any of these candidates is a vote for the Islamic Republic and a vote of confidence in the system," the hardline clerical leader's official Twitter account said.
With more than 12 million votes counted from the 50 million electorate, Rohani had tallied 51.8 percent of valid votes cast, according to Iran's interior ministry.
But state television channels said the winning candidate needed more than 50 percent of all ballots cast, including invalid ones. That would trim Rohani's vote to 50.03 percent, a much closer margin, but still enough to avoid a second-round run-off on June 21.
The atmosphere at Rohani's campaign headquarters was one of excitement with workers there preparing for victory, said a source close to the campaign. The Rohani campaign expected an announcement in the coming hours, the source said.
Electoral officials did not say from which districts the votes so far counted had come from.
Rohani's nearest rival was conservative Tehran Mayor Mohammad Baqer Qalibaf, a long way behind with 16.7 percent. Other hardline candidates close to Khamenei scored even lower.
Rohani's campaign was endorsed by centrist former president Akbar Hashemi Rafsanjani after the latter, a veteran rival of Khamenei, was barred from running by a state vetting body.
Rohani received a big further boost when reformists led by ex-president Mohammad Khatami swung behind him after their own lacklustre candidate Mohammad Reza Aref withdrew in his favour.
In contrast, several high-profile conservatives with close ties to the ruling clerical or Revolutionary Guards elite failed to unite behind a single candidate, suffering what appeared to be a decisive split in their support base as a result.
Voting was extended by several hours at polling stations across the country on Friday as millions turned out to cast their ballot in the first presidential race since the 2009 contest where allegations of fraud led to mass unrest.
State-run Press TV reported a turnout of about 80 percent.
Rohani came to prominence as Iran's nuclear negotiator in talks with Britain, France and Germany between 2003 and 2005 that Tehran Iran agree to suspend uranium enrichment-related activities, easing Western pressure at the time.
He left the post when Ahmadinejad came to office in 2005, enrichment activity resumed and there has been virtually no progress in intermittent talks since then. The result has been that international sanctions have been stepped up against Tehran, seriously damaging its heavily oil-dependent economy.
Rohani is an important bridge between hardliners around Khamenei who oppose any accommodation with the West and reformers sidelined for the last four years who argue the Islamic Republic needs to be more pragmatic in its relations with the outside world and change at home in order to survive.
Rohani, a mid-level Shi'ite cleric, has impeccable revolutionary credentials and was active in the opposition that toppled the U.S.-backed shah in 1979. He also held prominent roles in Iran's 1980-88 war with Iraq, including as commander of national air defence, according to his official biography.
He remains on the Supreme National Security Council and is also on the Expediency Council and the Assembly of Experts, two eminent advisory bodies in Iran's multi-tiered power structure.
But he has also maintained close ties with Rafsanjani and was backed by Khatami, the reformist president from 1997-2005.
Security was tight during the election and campaigning subdued compared to the euphoric rallies that preceded the last presidential vote in 2009, when reformist backers thought they scented victory and the prospect of democratic change in Iran.
Those hopes were dashed when rapid announcements gave Ahmadinejad 63 percent of the vote, returning him to office and starting a series of protests that lasted for months and led to dozens of killings and hundreds of arrests.