How does the game determine a successful defense?

You've pretty much got it but I'll elaborate a little.

A successful offense is one in which the attacker gains at least 1 star. I'm not 100% sure of the specifics but my understanding is that you can gain 1 star for destroying the keep, 1 star for destroying 50% of the buildings (excluding the keep) and the final star for completely wiping out all buildings and towers (but not walls or decorations).