By Parisa Hafezi

ANKARA (Reuters) - A top adviser to Supreme Leader Ayatollah Ali Khamenei said on Thursday Iran will not yield to "useless" U.S. threats from "an inexperienced person" over its ballistic missile program.

U.S. President Donald Trump's national security adviser, Michael Flynn, said on Wednesday the United States was putting Iran on notice over its "destabilizing activity" after it test-fired a ballistic missile.

Trump echoed that language on Thursday, saying in a tweet "Iran has been formally put on notice" after his administration said it was reviewing how to respond to the launch that Iran said was solely for defensive purposes.

Iran said on Wednesday it had tested the new ballistic missile but said it did not breach a nuclear deal reached with six major powers in 2015 or a U.N. Security Council resolution that endorsed the accord.

"This is not the first time that an inexperienced person has threatened Iran ... the American government will understand that threatening Iran is useless," Ali Akbar Velayati said, without identifying any U.S. official specifically in his comments.

"Iran does not need permission from any country to defend itself," he was quoted as saying by the semi-official Fars news agency. Khamenei is the country's most powerful figure.

A U.S. official said Iran had test-launched the medium-range ballistic missile on Sunday and it exploded after traveling 630 miles (1,010 km). Iran said it had been a successful launch.

A series of tests conducted by Iran's elite Revolutionary Guards Corps (IRGC) in 2016 caused international concern, with some powers saying any launch of nuclear-capable ballistic missiles would violate U.N. Security Council resolution 2231.

NUCLEAR DEAL

The IRGC maintains an arsenal of dozens of short and medium-range ballistic missiles - the largest in the Middle East, according to the London-based International Institute for Strategic Studies.

Under the nuclear agreement, most U.N. sanctions were lifted a year ago. But Iran is still subject to an U.N. arms embargo and other restrictions, which are not technically part of the deal.

Trump has frequently criticized the Iran nuclear deal, which restricts Tehran's nuclear activities in exchange for the lifting of the sanctions, calling the agreement weak and ineffective. He tweeted on Thursday that Iran "should have been thankful for the terrible deal the U.S. made with them".

Iran's Defence Minister Hossein Dehghan told the semi-official Tasnim news agency on Thursday: "The missile test on Sunday was successful ... the test was not a violation of a nuclear deal with world powers or any U.N. resolution."

German newspaper Die Welt, citing unspecified intelligence sources, reported on Thursday that Iran had tested a home-made cruise missile called "Sumar" that is capable of carrying nuclear weapons.

Tasnim news agency two years ago published pictures of the Sumar missile, reporting that it was successfully test-fired.

While Iran says its missile program is aimed at displaying the country's "deterrent power and its ability to confront any threat", some IRGC commanders have said that Iran's medium-range ballistic missiles were designed to be able to hit Israel.

Iran refuses to recognize Israel.

(Writing by Parisa Hafezi; Editing by Alison Williams)