A US defence official confirmed the launch, saying that the missile appeared to be consistent with Tehran's older Ashura models, long known to US intelligence.
Ahmadinejad, whose moderate challengers in the June 12 vote accuse him of isolating Iran with his anti-Western speeches, said the country had the power to send any attacker "to hell".
The launch came within hours of Iran's constitutional watchdog approving four leading candidates to stand in the election.
Ahmadinejad will seek re-election alongside moderate challengers Mirhossein Mousavi, Iran's former prime minister, Mehdi Karoubi, the former parliament speaker and Mohsen Rezai, the former head of Iran's Revolutionary Guards.
The four candidates were approved after being screened for their allegiance to Iran's Islamic government system and "absolute obedience" to the country's most senior authority, Supreme Leader Ayatollah Ali Khamenei.
More than 450 hopefuls had registered out of which 42 were women. No women passed a test to stand in the election.
Reformists believe a high turnout would give them a better chance to win the vote, but they say state media have not given sufficient coverage of the election to mobilise Iranian voters.
|Presidential Candiates top left to bottom right: Ahmadinejad, Mousavi, Karoubi and Rezai [AFP]
Ahmadinejad's rivals say his trips across Iran ahead of the authorised campaigning period are illegal and should be stopped. The government has refused.
State radio and television have denied being partial.
About 46 million Iranians over 18 years old are eligible to vote in Iran's tenth presidential election since the 1979 Islamic revolution.
The three other candidates have said Iran needs to have interaction and a "policy of detente" with the West.
Ahmadinejad came to power in 2005 vowing to share out oil wealth more fairly, but critics blame him for disappointing economic growth and high inflation.
However, his promises of a fairer redistribution of income still resonate with the poor.
Ahmadinejad's only conservative rival, Rezai, has criticised the president's "adventurous" foreign policy and his economic policy, saying Ahmadinejad would "drag the country over a cliff" if re-elected.