DUBAI/BEIRUT (Reuters) - Supreme Leader Ayatollah Ali Khamenei denounced the heated rhetoric of Iran's presidential election campaign on Wednesday as "unworthy", a thinly-veiled rebuke of pragmatist President Hassan Rouhani's attacks on his main conservative challenger.

The withdrawal of other conservative candidates has turned Friday's election into an unexpectedly tight two-horse race between Rouhani, 68, and hardline cleric Ebrahim Raisi, a 56-year-old protege of the supreme leader.

Khamenei's intervention could help sway the vote by signaling dissatisfaction with Rouhani's conduct.

"In the election debates, some remarks were made that were unworthy of the Iranian nation. But the (wide) participation of the people will erase all of that," Khamenei told an audience on Wednesday, according to his own website.

The two main rivals have traded charges of graft and brutality on live television with an open vehemence unseen in the near 40-year history of the Islamic Republic.

Separately, Rouhani on Wednesday warned the Revolutionary Guards Corps, Iran's most powerful military force, and the Basij militia that it commands not to meddle in the election.

"We just have one request: for the Basij and the Revolutionary Guards to stay in their own place for their own work," Rouhani said in a campaign speech in the city of Mashhad, according to the Iranian Labour News Agency (ILNA).

Rouhani quoted the late Ayatollah Ruhollah Khomeini, founder of the Islamic Republic, who he said had warned the armed forces against interfering in politics.

PUSHING LIMITS OF DEBATE

While Khamenei did not mention any candidate by name, his criticism appeared aimed in particular at Rouhani, who during a debate last week went beyond what is normally considered permissible to cast his foes as power-hungry pawns of the security forces.

"Mr. Raisi, you can slander me as much you wish. As a judge of the clerical court, you can even issue an arrest order. But please don't abuse religion for power," Rouhani said at one point. At another point he said to Raisi: "Some security and revolutionary groups are bussing people to your campaign rallies ... Who finances them?"

Story continues

For his part, Raisi, a long-serving member of the judiciary who was one of four judges who sentenced thousands of political prisoners to death in the 1980s, attacked Rouhani for failing to deliver promised improvements to the economy.

Under Iran's ruling system, Khamenei, who is 77 and has been in office since 1989, has more authority than the elected president but is traditionally expected to remain above the fray of day-to-day politics. He has generally limited his comments about the election to calling for a strong turnout.

THOSE WHO CUT OUT TONGUES

Rouhani came to power four years ago with more than three times as many votes as his nearest rival, on promises to reduce Iran's international isolation and grant more freedoms at home.

His main achievement has been a deal with global powers to lift economic sanctions on Iran in return for curbs to its nuclear program. But widespread economic improvement has yet to materialize, and hardliners accuse him of selling out Iran's interests too cheaply to the West.

The main obstacle to Rouhani's bid for a second term is apathy from reformist voters, many of whom now say they are disappointed by the slow pace of change.

Normally known as a mild-mannered pragmatist rather than a gung-ho reformer, Rouhani has tried to fire up the pro-reform camp with speeches that break taboos by making open references to human rights abuse by the authorities.

He alluded to hardliners last week as "those who cut out tongues and sewed mouths shut".

If no candidate wins 50 percent of the vote on Friday, a run-off will be held a week later.

Although the unelected supreme leader holds ultimate authority in Iran and all candidates must be vetted by a hardline clerical body, elections are nevertheless hotly contested and have the power to deliver change within a system of government overseen by Shi'ite Muslim religious authorities.

In 2009, hundreds of people died and thousands were arrested in protests after reformists disputed the electoral victory of hardline president Mahmoud Ahmadinejad. The two main reformist candidates from that vote remain under house arrest.

Tehran residents said police deployments appeared to have been beefed up in some areas of the capital, a normal practice ahead of national polls in Iran, to prevent unrest.

(Reporting by Dubai newsroom, William Maclean, Babak Dehghanpisheh; Editing by Samia Nakhoul and Peter Graff)