The remarks set Iran on a collision course with Western nations as the five permanent members of the UN Security Council debated how to deal with Iran's nuclear activities.
Khamenei told a meeting of Iranian diplomats on Tuesday that "The Islamic Republic of Iran considers retreat over the nuclear issue ... as breaking the country's independence which will impose huge costs on the Iranian nation.
"This path is irreversible and the foreign policy establishment has to bravely defend Iran's rights," he said.
After Tuesday's meeting at the UN, the council remained divided over what kind of statement should be made on Iran's nuclear programme.
A British-French draft demands that Iran should halt all uranium enrichment, which can be used to make nuclear arms, and calls for a report within weeks on Iran's progress towards answering questions about its nuclear programme.
Russia and China say the draft does not leave enough room for diplomacy and focuses too much on possible Security Council action.
Jack Straw, the British foreign secretary, called for a "robust and determined" stance from the UN and said his country would consider pushing for a weapons embargo against Iran if efforts to resolve the stand-off fail.
Khamenei's comments further dimmed already fading hopes for a Russian compromise proposal seen as the last chance for averting a stand-off at Security Council over Iran.
Tehran has been giving conflicting signals over the proposal, announcing over the weekend that it was no longer considering it, then saying talks with Russia were still underway.
Ahmadinejad is under pressure
from Iran's reformists
Khamenei intervened on Tuesday to lay down the law with one of his strongest statements on the nuclear issue, apparently intended at ending any compromising tone from moderates within the Iranian government.
The nuclear programme is a source of national pride in Iran, and even pro-reform figures have supported pursuing it.
But there has been growing reformist criticism of Ahmadinejad's foreign policy performance.
The Islamic Iran Participation Front, Iran's largest reformist party, said this week in a pamphlet that Ahmadinejad's call for Israel to be "wiped off the map" last year rang alarm bells in Western capitals and unnecessarily provoked the West against Iran.
The US and some in Europe accuse Iran of seeking to build nuclear weapons. Iran denies the charge, saying its programme is only to generate nuclear energy.
It insists on its right under the nuclear Non-Proliferation Treaty to fully develop peaceful nuclear technology, including uranium enrichment.
Russia's compromise proposal calls for uranium enrichment to take place entirely on Russian soil.
But negotiations have stalled after Tehran rejected Moscow's demand that it should completely suspend enrichment at home.