Teeth have nerves. That's why they can feel hot and cold, sensitivity and pain. The nerve inside a tooth is called dental pulp, which contains large nerve trunks and blood vessels.
When decays or cracks involve nerves, severe toothache may happen, especially at night time, which often ends up with a dental emergency. If the tooth can be saved, your dentist will recommend root canal treatment. The first step of root canal treatment involves removal of nerves (pulp extirpation), hence gets rid of the dental pain. The picture above shows the nerve was removed by a barbed broach. Then the root canal system will be cleaned, prepared and filled with gutta-percha.
To avoid this endodontic emergency, make sure to maintain a good oral hygiene with good brushing and flossing and visit your dentist regularly.