The United States and its allies are seeking to step up U.N. sanctions on Iran over its disputed nuclear plans, which the West sees as a bid to build nuclear arms. Iran denies this.
There has been persistent speculation Washington or Israel might launch strikes on Iran's nuclear sites, as neither country has ruled out military action if diplomacy fails to end the row.
"If anybody dares to breach the boundaries of the Iranian nation, the Iranian nation's holy land and Iran's legal interests, our armed forces ... will break his hand before he can pull the trigger," Ahmadinejad said.
He was speaking at a parade broadcast on state television to mark the start of the Iran-Iraq war in September 1980.
Hundreds of troops marched past the official podium, followed by military hardware, including the Shahab-3 missile, which television commentators said had a range of 2,000 km (1,250 miles), putting Israel in range.
Trucks drove past bearing large slogans reading "Down with Israel" and "Down with USA." Also on show were Ghadr and shorter range Shahab missiles, unmanned planes, artillery and rockets.
"Today, Iran is not in a position to show even the smallest flexibility against the bullying of the enemies. History has shown that those who wish ill for Iran will gain nothing but regret," he said.
"The enemies of humanity ... had imagined that by military attack and economic and scientific sanctions they could break down our revolution and our nation," he said, adding that Iran's enemies had "lost hope".
Analysts say the United States could unleash vastly superior firepower in any attack on Iran, but that the Islamic state could hit back by striking at U.S. interests in the oil-rich Gulf and neighbouring countries, including Iraq.
Ahmadinejad said that despite sanctions, Iran had nevertheless built up its ability to produce weapons.
"Those who deprived us of the simplest defensive technology and put economic sanctions on Iran, today ... they should look carefully and see the Iranian nation's armed forces and the defensive achievements of the Iranian nation," he said.
Iran, the world's fourth largest oil producer, says it wants to master nuclear technology to make electricity so it can preserve more of its vast oil and gas reserves for export.
But its failure to convince world powers of its peaceful intentions has prompted three rounds of limited U.N. sanctions. Washington is pushing for a fourth, but China and Russia -- two of the five veto-wielding council members -- are reluctant.