I've noticed that AI factions break their alliance with the recipient of an attack. I usually don't start a fight and make alliances first. However, once I get attacked, my allies cancel their alliance with me. The few times I was the aggressor, they cancelled their alliance with the other guy.

Also, if you have any ships in a territory that the enemy can destroy, you will get into war eventually. The Italians and Sicilians especially love to sink fleets weaker than theirs no matter what. You have to build more ships to protect yourself.