When other sides demand things off of you, do not click "accept this offer". Instead, click on "Counter-proposal", and then click "Forget this Deal". Then you will not have to give the opposing side anything, and you will not be attacked!!!
When another side wages war on you, the best thing to do is to fortify your cities with your best units. Instead of building Pyramids or Palaces, change all your Cities to produce Archers, Spearmen, or whatever is the best unit you have. Once you surround your Cities with these units, there is less of a chance of them being captured by the opposing sides.