Amit Sharma, an accused in a case, came to the court in connection with hearing in the matter, police said.
Sharma poured petrol on himself and before he could set himself ablaze, people and police personnel present nearby caughthold of him, they said.
He has been taken to a hospital for medical examination, police said.
Sharma is a one of the accused in a case which was lodged with Jawahar nagar police station for stone-pelting sometime back.