Resist compositions comprising nitrogen heterocyclic compounds having a pyrrole or nitrogen-bearing 5-membered ring structure and a polar functional group have an excellent resolution and an excellent focus margin and are useful in microfabrication using electron beams or deep-UV light.