First of all, just don't do it. It's better that way.
Before you even have the chance of losing it, let's go over what you can do before the llamas eat your passport. Doing a couple of these simple things pre-trip can potentially save your patootie before you even step across the border:
- Scan a copy of your identifying information, along with any country visa information.
- Save it on your computer, Dropbox it and email it to yourself.
- Print out a copy of those two important pages and bring it with you on your trip.
Your passport, as you should know, is the most important piece of identification you'll have with you. It can be useful carrying these printouts with you, especially if you have to leave some kind of identification with agencies and hotels, but don't yet want to part with your passport.
In case of the big "uh oh," due to negligence or theft, then you'll have to face a whole new set of actions. You'll be in a pretty pickle, but if your passport was stolen, the first thing you should do is report it to the authorities. (U.S. citizens can call the Department of State at 877-487-2778 toll-free.) Be warned that once you report it the embassy, it'll officially void and cancel your current passport.
In most cases, the hotel staff and local authorities can assist you with this process. Then you'll be faced with the task of finding your country's nearest embassy or consulate in person, which could or could not be in the same town. It's entirely possible you'll have to travel for this step, and even sort out new accommodation.
Once you arrive, you'll have to reasonably prove your identity (see: printouts), and go through the process of either applying for a new or temporary passport to be issued at the consulate. The process could take a week to several weeks, so be prepared to delay your travel plans if this happens. (Sometimes it does happen quickly.)
If you're also without funds, you'll most likely be asked to provide the names and contact information of people who can assist you until you get your stuff sorted out. It goes without saying, but you won't be able to leave the country until you have your new documentation in hand.
It would probably also be wise to monitor your credit history in case anyone uses your passport fraudulently. It's apparently been known to happen: but stolen passports do sometimes make it to people who are trying to misrepresent themselves.
Losing your passport is basically an expensive and timely affair that could have you changing your route out, as well as adding a few extra unplanned weeks to your trip — don't forget about the cost of accomodation. It's trite, but better safe than sorry.
UPDATE: I actually ended up losing my passport later, despite writing this!