TEHRAN – Iran's presidential candidates ended a hard-fought and bitter campaign on Thursday, the eve of an election which reformists hope will prevent hardline Mahmoud Ahmadinejad winning a second term.

The campaign has seen unprecedented political mudslinging and large rallies in Tehran by supporters of moderate former prime minister Mirhossein Mousavi, who a senior Revolutionary Guard officer accused of attempting a velvet revolution.

Friday's highly charged election could set the tone for Iran's relations with the West, concerned over its nuclear ambitions, and analysts say a victory for Mousavi could increase the prospect for Western investment in the Islamic Republic.

But for Iranians it is a chance to judge Ahmadinejad's economic record and his austere Islamist social agenda.

I think it's a neck-and-neck race (between Ahmadinejad and Mousavi), said one Tehran analyst who asked not to be named. It's difficult to think either of the two candidates will get above 50 percent tomorrow.

If none of the four candidates wins an outright majority on Friday the two leading candidates will go into a June 19 run-off, which the analyst said Mousavi had a good chance of winning.

But others predict a victory for the incumbent, based on his popularity among the rural poor. Ahmadinejad has a lot of support throughout the country, said Hamid Najafi, editor-in-chief of the conservative Kayhan International.

Mousavi supporters, wearing his bright green campaign colors, have poured onto the capital's streets for festive, nightly rallies unseen since the election 12 years ago of reformist cleric Mohammad Khatami.

Ahmadinejad supporters have held huge demonstrations of their own, expressing support for a leader who has handed petrodollars to the poor and defied Western pressure to suspend Iran's nuclear program.

The vibrant and largely good-natured rallies have contrasted with bitter political exchanges.

Ahmadinejad's opponents accused him of lying about Iran's economy, hit by rising prices and unemployment, while Ahmadinejad has enraged the powerful former president Akbar Hashemi Rafsanjani -- a Mousavi supporter -- by accusing him of corruption.

Rafsanjani wrote a public letter to Supreme Leader Ayatollah Ali Khamenei, urging him to rein in Ahmadinejad, and met Khamenei on Tuesday to express fears the election will be rigged, a leading moderate politician told Reuters.

Rafsanjani urged the leader to use his authority to make sure the election was a clean and healthy one, he said.

STREET DANCING

Mousavi, 67, an architect who has been out of the political spotlight for two decades, is backed by reformists and conservatives disenchanted with Ahmadinejad.

His outspoken wife has broken with convention to campaign openly and vocally alongside her husband, helping draw support from women and Iranians too young to remember his premiership in the early years of the 1979 Islamic Revolution.

His campaign has released a surge of youthful energy in Tehran. On Wednesday night women daringly threw off their headscarves, obligatory in Islamic Iran, and danced openly with men in the street -- in a direct challenge to 30 years of strict clerical rule.

But analysts say a Mousavi victory would be unlikely to trigger seismic change in a country where major policy issues are decided by the supreme leader, Khamenei.

Mousavi advocates detente with the West, a policy which could offer hope for progress in relations with the new U.S. administration of President Barack Obama, who has offered to engage with Iran if Tehran unclenches its fist.

Mousavi rejects western demands that Iran halt uranium enrichment but says the dispute should be resolved through talks with the West, which fears Iran's nuclear work could be used to make bombs. Iran, the world's fifth-biggest oil exporter, says its nuclear program is peaceful.

The United Nations has imposed three sets of sanctions on Iran because of its refusal to stop enriching uranium, including freezing assets of Iranian companies accused of involvement in the nuclear program.

A Mousavi victory would likely... lead some investors to begin exploring the Iranian market as a possible medium-term option, said Cliff Kupchan of Eurasia risk consultancy.

(Additional reporting by Fredrik Dahl; Writing by Dominic Evans; Editing by Diana Abdallah)