Mousavi, surrounded by hundreds of supporters, was trying to reach the graveside of Neda Agha Soltan, a young woman whose shooting death at an anti-government rally last month was caught on video that became one of the iconic images of the upheaval.
"Mousavi was however not allowed to recite the Koran verses said on such occasions and he was immediately surrounded by anti-riot police who led him to his car," a witness said as people chanted "Ya Hossein! Mir Hossein!".
"At the same time mourners also surrounded his car and were not allowing him to go. The police then started pushing the mourners after which Mousavi drove off," the witness said, adding that several were detained.
Mousavi and Mehdi Karroubi, who have waged a defiant protest campaign since losing to Ahmadinejad in what they brand a rigged election, had announced they would visit the cemetery after authorities banned another memorial ceremony.
Meanwhile, Iranian riot police beat and arrested mourners who staged a defiant gathering at a cemetery, witnesses said.
Police used sticks, batons and belts on some of the hundreds of people at the graveyard where protesters are buried and later forced opposition leader Mir Hossein Mousavi to leave and arrested several mourners, they said.
The cemetery became a flashpoint as crowds gathered to mark the 40th day since the death of Neda Agha-Soltan, a young woman who came to symbolise the protest movement against the re-election of President Mahmoud Ahmadinejad.
Witnesses said about 150 police and some members of the Islamic Basij militia were in and around the Behesht-e Zahra cemetery south of Terhan before Mousavi arrived and walked up to Neda´s grave.
Witnesses said dozens of policemen were also at the Grand Mosalla in Tehran, a venue used for religious functions where the opposition had planned to hold the ceremony.
A graphic Internet video of Neda bleeding to death on a Tehran street on June 20 was seen around the world and triggered an outcry over the Iranian crackdown on demonstrators.
About 40 people, wearing green wristbands and T-shirts -- the signature colour of Mousavi´s election campaign -- were earlier seen standing around Neda´s grave which was decorated with candles and flowers.
Mousavi, a prime minister in the post-revolution years who was Ahmadinejad´s main challenger, has consistently refused to acknowledge his rival´s victory, saying it was a "shameful fraud."
Hundreds of thousands of people poured on to the streets of Tehran after the election result and in the ensuing violence about 30 people were killed, scores wounded and several thousand arrested, Iranian officials say.
Israel downs Iranian drone and strikes Syria, F-16 crashes