Al-Sha'bi said that Sharahah al-Hamdaniyyah, who had committed adultery, was brought to Sayyiduna Ali (may Allah be pleased with him); then he sent her back so that she could give birth. When the child was born, he said: Call her closest female relative. She was called, then the child was given to her; then he (may Allah be pleased with him) first flogged her, then stoned her, and said: I have flogged her on account of the Book of Allah and stoned her according to the Sunnah of the Messenger (peace and blessings be upon him). Then he said: Any woman whose adultery becomes evident through confession or pregnancy, the imam should be the first to stone her, then the people; and if her adultery became evident through testimony, then the witnesses should stone first, then the imam and then the people.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الحدود / 16962