By Parisa Hafezi

ANKARA, April 27 (Reuters) - Iranian President Hassan Rouhani defended his economic record on Thursday, three weeks ahead of Iran's presidential election, and called for further engagement with other countries as the key to economic growth.

His remarks contrasted with the view of the country's ultimate authority, Supreme leader Ayatollah Ali Khamenei, who has called on the six presidential candidates not to rely on foreign investment to revive the country's economy.

The pragmatist president, who is seeking re-election in the May 19 vote, said Iran's economy had improved since his election in 2013 on a platform of ending the country's isolation and creating a freer society.

"We should avoid scaring away foreign and domestic investors ... we can attract 140 billion dollars of investment that can help to tackle unemployment," Rouhani said in a live radio programme.

"The living standards of Iranians have improved ... incomes of pensioners and those on welfare support have increased in the past four years."

Khamenei and his hard-line allies have criticised Rouhani's policy of rapprochement with the West since 2015, when Iran reached a agreement on Iran's nuclear power programme with six major powers that ended Tehran's years of political and economic isolation.

Khamenei has ruled out any further rapprochement with the United States since that deal, under which Iran curbed its nuclear programme in exchange for lifting of sanctions.

"Four years ago, I promised our people to end Iran's diplomatic isolation ... we cannot resolve our economic problems only by chanting slogans," Rouhani said, referring to his hard-line challengers' campaign promises of creating millions of jobs per year. "To tackle unemployment, we need investment."

The confrontation between Rouhani and his main hard-line challenger, Ebrahim Raisi, has intensified in recent days. Raisi has rejected Rouhani's economic record and his pursuit of detente with the West. A mid-ranking cleric, Raisi was one of the four sharia judges of the so-called Death Commission that sanctioned the massacre of thousands of political prisoners in 1988. He is a former student of Khamenei and some insiders believe Rouhani will face tough competition to hold on to office for a second term.

"Iran's election result is unpredictable ... but it seems Raisi has a better chance to win as he is backed by Khamenei and his allies," said political analyst Hamid Farahvashian.

Another candidate, the conservative mayor of Tehran Mohammad Baqer Qalibaf, criticised Rouhani's economic policy, saying "the gap between poor and rich has widened in the past four years".

"Iran's main enemy today is the recession, high unemployment rate and inflation," Qalibaf, a former commander of Iran's elite Revolutionary Guards (IRGC), said in a televised speech.

Qalibaf praised the head of Iran's Quds Force, the elite extra-territorial special forces arm of the IRGC, Qasem Soleimani, for "keeping enemies away from Iran".

Soleimani, who reports to directly Khamenei, has been overseeing ground operations against insurgents in the Middle East, including Syria and Iraq. Iran supports Syrian President Bashar al-Assad against various rebel groups in that country's civil war.

"Not the nuclear deal but national heroes like Soleimani ... have fended off military threats against Iran," he said, referring to Rouhani's remarks that the nuclear agreement had eliminated threats of military strike against Iran.

Israel, which Islamic Iran refuses to recognise, had threatened to attack Tehran's nuclear sites if sanctions and diplomacy failed to curb Tehran's nuclear ambitions.

(Writing by Parisa Hafezi; Editing by Larry King) ((parisa.hafezi@thomsonreuters.com; +90 532 176 3452; Reuters Messaging: parisa.hafezi@thomsonreuters.com))