Many of Mousavi's supporters who filled the 18km-long Vali Asr, an avenue which runs north to south through the capital, wore banners, headscarves and ribbons in the green that has become the campaign's colour.
"This is a message to all of Tehran's population," Sharan Kjarimi, a 32-year-old industrial engineer, said.
Mousavi addressed the southern end of the rally saying: "We've gathered here because people are tired of lies ... the human chain is a symbolic rejection of lies being said to the people."
The crowds chanted "Ahmadini bye-bye" and "If they don't cheat, Mousavi will win."
The crowd supporting Ahmadinejad called Mousavi a "liar" and criticised Akbar Hashemi Rafsanjani, a former reformist president, who is supporting his campaign.
"Hashemi and his sons are looters who have stolen public money!" and "Death to Hashemi!" they said.
Ali Rezae, a supporter of the president, praised him for fighting on behalf of Iran's interests.
"He won our national dignity in international arenas," he said outside the mosque.
Al Jazeera's Teymoor Nabili, reporting from Tehran, said: "The 180,000 people estimated to have come here have blocked all the streets and now he can't get in."
"What this demonstrates is how much support there remains for Ahmadinejad, despite the fact that people have been saying that his campaign has been struggling, and doubtless he will use this to show that he has still got the momentum to beat his challenger."
Sixty-five per cent of Iran's population, or about 46 million people, are eligible to vote
Turnout in the last election was around sixty per cent
Just over 13 per cent, or six million of those eligible to vote, will be first time voters
Three-quarters of the population are under the age of 30 and the voting age is set at 18
Ahmadinejad came under attack over security and the state of the economy on Monday in the latest televised debate between candidates.
"One of the main faults of Mr. Ahmadinejad is that he thinks he knows everything about every subject," Mohsen Rezai, a conservative challenger and former head of the Revolutionary Guards, said.
"If he is in charge of the nation's security, then our nation will face serious and irreparable danger."
He criticised Ahmadinejad for sacking a number of senior officials, which he said had destabilised the economy, and accused him of underestimating the country's inflation rate.
But Ahmadinejad blamed the economic situation on "high global inflation" and said that the government had assured that people's salaries had risen in line with inflation.
"We are in a race with the rest of the world and the main thing is that the implementation of the [economic] plan must be preserved," he said.
A fourth candidate, Mehdi Karroubi, a reformist and former parliamentary speaker, is also standing in the June 12 election.
He said on Tuesday that he will resist calls for him to withdraw from the election in order to unify the reformists' vote in favour of Mousavi, the main challenger to Ahmadinejad.
"I will never withdraw ... I believe the larger the number of candidates, the better," he told a news conference.