Qom, Iran (CNN) -- Tens of thousands of people chanted anti-government slogans Monday before the funeral of a top Iranian cleric who turned into one of the regime's most vocal critics, a witness said.
They shouted "death to the dictator!" outside the home of senior Iranian dissident Grand Ayatollah Hussein Ali Montazeri, who died early Sunday. He was 87.
Montazeri -- a key figure in Iran's Islamic Revolution 30 years ago -- was perhaps the most prominent cleric who publicly criticized the presidential elections last June that returned hard-liner Mahmoud Ahmadinejad to the presidency.
Protesters and mourners began to gather near his home in this holy city around 7 a.m., swelling to huge numbers by the time the funeral procession began, said the witness.
Both uniformed and plain clothes security forces turned out for the funeral, with the undercover officers arriving in several buses and mingling with the crowds.
The witness did not see any clashes but said tensions were high as protesters stood and chanted just steps away from security forces.
Many of the protesters and mourners had driven to Qom, where Montazeri lived, from Tehran and other cities hundreds of miles away, the witness said. Mourners from Najafabad, Montazeri's hometown, passed out dates, an Iranian tradition at funerals.
The night before the funeral, chants of "God is great" -- which the opposition uses as a rallying cry -- could be heard in several Tehran neighborhoods. The chants were louder than usual, witnesses said.
Around 300 to 400 people gathered at Tehran's Mother's Square and lit candles on Sunday night in memory of Montazeri, several sources told CNN. The witnesses did not see any clashes between security forces and the people at the gathering.
CNN is not naming its sources to protect their security.
Writing on his Web site after the disputed June presidential elections, Montazeri described the street protests that followed the polling as a challenge to the "very legitimacy of the Islamic Republic."
His death is "a terrible blow for the (reformist) green movement and everybody who has been active these past few months," said Mehrdad Khonsari, a senior research consultant at the Centre for Arab and Iranian Studies in London.
"He was a very senior grand ayatollah with very good revolutionary credentials, and a very vocal critic of the ruling establishment," Khonsari said.
"He was a major thorn in the back of (Iranian Supreme Leader Ayatollah Ali) Khamenei. He was a bastion for all the people opposing the excesses of the system," even within the ruling establishment, he said.
In the last six months, Montazeri had become the voice of the green movement on key foreign policy issues, Khonsari said. The cleric was able to comment more freely than reformist presidential candidates.
Montazeri, for example, took a public stand against nuclear weapons in October, issuing a fatwa, or religious edict, declaring them to be "un-Islamic" and instructing Muslims to take the lead in banning them, said Nazenin Ansari, diplomatic editor of the weekly newspaper Kayhan in London.
Iran's nuclear program has been the subject of intense international concern, with the United Nations considering expanding sanctions against the Islamic state despite its insistence it does not intend to build a bomb.
"He has a very large public following especially since the June elections and all his statements in favor of human rights," Ansari said
Montazeri's Web site called for a funeral procession from his home to the Massoumeh Shrine in Qom, the holy city where he lived, starting at 9 a.m. on Monday (12:30 a.m. ET).
Demonstrations at the burial could spill over into the capital, Ansari said.
"Qom is very close to Tehran and this is a major event," she said, adding that it is difficult to predict what would happen. "It would be questionable how a lot of the foot soldiers of the revolution would react."
The timing of his death could also be significant, she said, since it comes in the month that first saw the demonstrations that spiraled into the revolution that toppled the monarchy and brought the Islamic regime to power.
Montazeri was once a confidant of Ayatollah Ruhollah Khomeini, who led Iran for a decade after the revolution.
He studied under Khomeini and then acted as his representative in Iran after Khomeini was exiled by the shah for criticizing the monarchy, Ansari said. Montazeri, too, was jailed and exiled.
After the revolution, he was the heir apparent to Khomeini, and played a key role in writing Iran's constitution as the first chair of the powerful Guardians Council. He was also the leader of Friday prayers in Tehran, one of the most public and influential pulpits in the country.
But he was supplanted by the current supreme leader, Ayatollah Ali Khamenei, and was placed under several years of house arrest in 1997.
"His problems with Khomeini started in the summer of 1988 when they started executing... thousands of leftist prisoners," Ansari said. "He never was in agreement with that, and then he started to fade" from power.
"Once Khamenei became leader, Montazeri objected," she said.
Montazeri said Khamenei "was elevated above his (religious) qualifications," pointing out that he had not earned the title of ayatollah. "It was then he was arrested."
Recently he has objected to the current regime's characterization of his one-time mentor Khomeini as a saint, she added.
And following the disputed elections in June, "he issued a ground-breaking fatwa articulating the policies of the (reformist) green movement to the world.
Montazeri had been equally critical of the parliamentary electoral process in 2004, arguing in favor of reformist candidates.
Sitting behind his desk with a government minder in the room, he said then that Iran's Islamic revolution had lost its way.
"Even I, who used to be a leading figure in the revolution, have not the right to speak out," he said. "Authoritarianism will never last long. The gentlemen in power must submit to the wishes of the people, or they will be swept away."
CNN's Reza Sayah and Richard Allen Greene contributed to this report.