TEHRAN, July 19 (Reuters) - Russian President Vladimir Putin had talks with Supreme Leader Ayatollah Ali Khamenei in Iran on Tuesday, the Kremlin leader's first trip outside the former Soviet Union since Moscow's Feb. 24 invasion of Ukraine.

In Tehran, Putin also held his first face-to-face meeting since the invasion with a NATO leader, Turkey's Tayyip Erdogan, to discuss a deal that would resume Ukraine's Black Sea grain exports as well as the conflict in northern Syria.

Putin's trip, coming just days after U.S. President Joe Biden visited Israel and Saudi Arabia, sends a strong message to the West about Moscow's plans to forge closer strategic ties with Iran, China and India in the face of Western sanctions.

Khamenei called for long-term cooperation between Iran and Russia, telling Putin that the two countries needed to stay vigilant against "Western deception", Iran's state TV reported.

He said Putin had ensured Russia "maintained its independence" from the United States and that countries should start using their own national currencies when trading goods.

"The U.S. dollar should be gradually taken off global trade, and this can be done gradually," Khamenei said during the meeting, in a spartan white room with an Iranian flag and a portrait of late revolutionary leader Ayatollah Khomeini.

Despite the suffering endured by ordinary people in war, Khamenei said Moscow had little alternative in Ukraine. "If you had not taken the initiative, the other side (West) would have caused a war on its own initiative," he told Putin.

Washington said Putin's trip to Tehran showed how isolated Russia had become in the wake of its invasion of Ukraine.