Srimad Bhagavatam Canto 03, Chapter 14, Text 27

SB 3.14.27

yasyanavadyacaritam manisino
 grnanty avidya-patalam bibhitsavah
nirasta-samyatisayo ’pi yat svayam
 pisaca-caryam acarad gatih satam
 
Translation by His Divine Grace A. C. Bhaktivedanta Swami Srila Prabhupada: 
 
Although no one in the material world is equal to or greater than Lord Siva, and although his unimpeachable character is followed by great souls to dismantle the mass of nescience, he nevertheless remains as if a devil to give salvation to all devotees of the Lord.
 
Purport by His Divine Grace A. C. Bhaktivedanta Swami Srila Prabhupada: 
 
Lord Siva’s uncivilized, devilish characteristics are never abominable because he teaches the sincere devotees of the Lord how to practice detachment from material enjoyment. He is called Mahadeva, or the greatest of all demigods, and no one is equal to or greater than him in the material world. He is almost equal with Lord Visnu. Although he always associates with Maya, Durga, he is above the reactionary stage of the three modes of material nature, and although he is in charge of devilish characters in the mode of ignorance, he is not affected by such association.
Srimad Bhagavatam Canto 03, Chapter 14, Text 26
Srimad Bhagavatam Canto 03, Chapter 14, Text 28