Every embassy runs an emergency consular line that operates outside office hours, and finding it takes one minute: search your foreign ministry's official website for your embassy in the destination country, and save both the switchboard and the after-hours emergency number in your phone before you travel.
Know what consular services can and cannot do. They can issue emergency travel documents when passports are lost or stolen, visit and monitor citizens who are arrested, provide lists of local lawyers, doctors and translators, contact your family with your consent, and coordinate assistance during disasters and evacuations.
If you are arrested, you generally have the right under international consular conventions to have your embassy notified; ask for that explicitly. For disasters, registering your trip in advance with your government's traveler enrollment program means the embassy knows you are in-country and can reach you with instructions. Dual citizens should note the embassy of one nationality may have limited standing in the country of the other.