Instead of trying to avoid this situation(although it would help to learn to avoid it) why not try to solve it in the good old fashioned imperial tradition? Start claiming land and annexin your neighbors? Upon the increase in both percieved and actual power they will all start to back out. More often, once the original dow-er backs down the rest scrambkle to be the first to peace offer, often for little or no cost to you (sometimes they tribute you if they are weaker militarily).
Try keeping advanced scouts(literally scouts or explorers, expendable units like warriors, workers, spys, etc.) at your borders, at bottlenecks, at strategic points in countries with an ob agreement with you.
Try to keep four or five units a city when at peace (I use less, but I do this more often and am at peace less, frankly). Improve border tiles first in the event of war your workers will be safe inside your boders. Keep a few counter-uints around, and a small stockpile of gold for lubrication of mongers. Pick one side (one religion, one friend, one group) and stick HARD to them. Like glue. If they ask you to switch religions, do it. if they ask you to tinkle on a friendly civ, do it. If they ask for a reasonable tech for free, do it. Small price to pay for a solid ally, who will help you win wars and trade consistently.
Specialize cities if you haven't. You do not have to start out with crazy schemes... but pick a city and devote it to capital, pick another and mine it out for production(military units often come from these), use a third for gp farming (high pop and maximize gp/turn modifiers(or rather one specific gp/turn type)).
Plan your six or seven starter cities prior to placing your second. esp. if you want to peacemonger early on. Remember that animal barbs cannot harass your worker if he stays inside your borders.
Sign OB agrrements carefully. When they cannot see your cities they cannot see your defenses. follow the movement of enemy or neutral stacks carefully. Often they seem (to me) to feint and fake, or to test how carefully you pay attention.
Remember that if you really piss off somebody they will dow you as soon as they can afford a decent military and bring it up to your borders. Weaker civs will team up to do so, and bribed civs will take half-hearted swings at you, even if they do not hate you.
Plan for the Astro expansion carefully, if you have a New World of sorts. Start to stockpile settlers and warriors, workers prior to building ocean-bound vessels. Reg barbs I rarely have too much difficulty with, but on a sufficient landmass w/ragers I often find two or sometimes three of my superior units have difficulty defending a new settlement while a worker tries to improve it.
A navy counts as military, and while the ai is a little slow with it they can surprise you. Keep more than a token fleet at your disposal.
Nukes may be powerful, but airplanes are easily just as effective. Zepplins are a must for me asap(well...quickly).