Mehdi Karroubi's armoured car was hit at least twice as it pulled away from the crowd. Mr Karroubi was unhurt.

The shooting was an ominous development in the seven months of internal strife that have engulfed Iran since the presidential election in June.

Mr Karroubi (72) has been attacked with bricks and tear gas, but never with bullets, and in recent days the regime has sharply increased its efforts to crush a resurgent opposition. It has fired on demonstrators and staged rallies that have demanded the execution of Mr Karroubi and Mir-Hossein Mousavi, the other leader of the so-called Green Movement.

Mr Karroubi, one of the defeated presidential candidates, ran into trouble on Thursday when he visited the town of Qazvin, 80 miles west of Tehran, to attend a mourning ceremony for opposition demonstrators shot by the security forces.

As he was talking to a local cleric in his home, hundreds of government supporters, many of them Basij militiamen, surrounded the building and chanted "Death to Karroubi".

After four hours the police cleared a way through for Mr Karroubi. Pro-government websites said that his car "left under a hail of stones, eggs and tomatoes", but opposition sites said that it was also shot at.

"One of the two shots hit the windshield and the other hit the back window," Mr Karroubi's son, Hossein, said.

Mr Karroubi said: "My bodyguards did not fire back because, unlike the assailants, they would have been brought before the courts and faced prosecution."

Mr Karroubi has talked recently of the possibility of assassination and insisted that the threat will not deter them.