Imam Ali un Naqi (as) served the longest period of Imamate (besides the 12th Imam) - 34 years which can be divided into two parts - 17 years of freedom and 17 years under arrest.
In 234 A.H. came one of the most tyrannical rulers of the Abbasid Khilafate - Mutawakkil. He ruled with tyranny, killing, looting and terrorising especially those who were the followers of Ahlulbayt. Mutawakkil is also the one who ordered the desecration of the grave of Imam Husayn (a.s.) wanting to remove Imam`s body and burn it (He did not succeed). He tried running water over the grave so no traces of the grave would remain but was unsuccessful. He ordered that all those wanting to visit Kerbala would have their fingers cut off, then hand and feet cut then only be able to go if one other from the family was killed. Imam still asked Shias to visit Kerbala. When Mutawakkil saw that all had failed and it did not discourage the visits than he banned all visits to Kerbala completely.