It was the first time Khamenei, who has the last word on all state matters in the Islamic Republic, had aired his views on Iran's deal. According to the agreement struck with three European foreign ministers, Tehran would suspend uranium enrichment and sign up to snap nuclear checks.
"If we reach the point that Iran's national interests and values are threatened, we will not hesitate to stop our co-operation," he said on Iranian state television on Monday.
"Anyone who ever tries to challenge Iran's peaceful nuclear programme will be slapped in the face," he said.
Iran strongly denies US charges that its nuclear programme is a smokescreen for developing atomic weapons.
Khamenei said Iran had not bowed to pressure in striking a deal with the foreign ministers of Britain, France and Germany who wanted proof that Tehran was not seeking nuclear weapons.
"Iran made a correct and wise decision and it does not mean surrender. It neutralised the American and Zionist plot," he said in a speech to senior officials.
Some Iranian hardliners have criticised the deal to open up Iran's nuclear installations to snap checks, which they view as a concession to foreign pressure.
"Iran made a correct and wise decision and it does not mean surrender. It neutralised the American and Zionist plot"
Ayat Allah Khamenei
supreme leader, Iran
But Khamenei said Iran's interests had not yet been harmed. "When I feel that a step has been taken against the interests of the system, I will end co-operation," he said.
Washington said on Monday it wanted "decisive action aimed at ensuring full Iranian compliance with its safeguards obligations" when International Atomic Energy Agency (IAEA) chief Mohammad ElBaradei presented his report on Iran in November.
"Threats from Iran to end such cooperation... would be gravely troubling and would further deepen the international community's concerns that Iran continues to have something to hide from the IAEA," State Department spokesman Adam Ereli told reporters in Washington.
But a Western diplomat in Vienna said it was almost inconceivable that Iran would end co-operation with the IAEA, as a number of hardline Iranian officials had threatened.
"They are not so stupid," said the diplomat.
If Iran were to end its co-operation with the agency, the diplomat said the IAEA board would not hesitate to report this to the UN Security Council, which could impose sanctions.
The diplomat said Iran would probably escape being reported to the Security Council at the IAEA's governing board meeting in November, despite repeated failures to inform the agency about its past nuclear activities and facilities.
Iran in October handed over what it called a "comprehensive and transparent" declaration of its nuclear programme to the IAEA. ElBaradei said on Sunday the agency was in the process of verifying the declaration.