It happens if you don't form alliances. You have to negotiate treaties of mutual protection with some of them so that not all of them will gang up against you
I usually play aggressively and try to form alliances with the most powerful civs and/or those civs I don't plan to assimilate later on.
For ex, in my last game Egiptians and Iroquis had an alliance and i needed coal that was only in their territory. So I formed an alliance with England and germany against them (I had to pay them big bucks to have them accept the alliance with me but it paid off later on).
As soon as the war starts the brits and germans join me against the egiptians and Iroquis. Next thing I know everybody else declares war with us against them (brits and germans had their own alliances that kicked in a few turns later).
Next thing I know the Man-O-War and german ironclads start hammering the Egiptian and Iroquis coasts and sink any of their ship.
It was pretty cool to fight side by side with the AI. Those guys are brutal, let me tell you. They bombed the hell out of the egiptian coasts.
Keep them friendly and form alliances. Usually they don't attack you if you are well connected. If they do...
they asked for it...
Hope this helps
Yoda