But if the USA does attack, he warned, "We will raze Tel Aviv and Haifa to the ground".
Dismissing calls that Iranian regional influence should be curbed, the deputy commander of Iran's Islamic Revolutionary Guards Corps (IRGC) was quoted as saying on February 11 that "the enemy can not ask us to leave the region".
One banner read: "Much to the dismay of America, the revolution has reached its 40th year".
Hundreds of thousands of Iranians celebrated the anniversary all over the country.
"We have not asked and will not ask for permission to develop different types of. missiles, and will continue our path and our military power", President Hassan Rouhani said in a speech at Tehran's Azadi (Freedom) Square.
Demonstrators braved rain and snow on Monday, carrying Iranian flags and chanted slogans such as "Death to Israel, death to America".
Iran displayed its ballistic missile capabilities during a parade, including the Zolfaqar, a ground-to-ground missile with a 700 km (435 miles) range and the Qiam, with a range of 800 km, according to Tasnim news agency.
Iran's 1979 Islamic Revolution initially inspired both Islamic militants and Islamists across the Mideast.
Iran was determined to expand its military power and ballistic missile programme despite pressure from hostile countries, state TV reported Rouhani as saying.
The state has played up this year's anniversary as 40 is symbolic of maturity in the Islamic tradition and the age at which Prophet Mohammed received revelations from God.
According to Channel 12 news, the factory is meant to focus on producing precision missiles, dramatically upgrading the threat to Israel from the vast arsenal of rockets and missiles deployed against it in southern Lebanon by Iran's proxy, Hezbollah.
Pictures on social media showed some people also demonstrating against corruption, unemployment and high prices.
US President Donald Trump pulled out of Iran's 2015 nuclear deal with world powers previous year and re-imposed sanctions on Tehran - dealing a blow to the country's economy.
The Israeli prime minister's comments came in direct response to IRGC political affairs spokesman Yadollah Javani, who warned earlier on Monday that Iran would attack Israel if threatened by Washington. "Iranian people have and will have some economic difficulties but we will overcome the problems by helping each other", he said.
Referring to Iran as "the Mother Land", Rouhani said that during the rule of "the traitor Qajar dynasty 205 years ago", large portions of lands were separated from Northern Iran and the caucuses.
Today, the United States, its Arab allies and Israel are trying to counter Tehran's growing influence in the Middle East, where it has proxies in Syria, Lebanon and Yemen. -Gen. Hossein Salami, deputy head of Iran's Revolutionary Guards.