You have to get more trophies from attacking than what you lose in defenses to stay in Legend League.
The amount of trophies you gain from an attack is determined by how many Stars you get and how much damage you manage to inflict. You have to inflict at least 10% damage to start gaining trophies from an attack. Scoring less than 1-Star in battle does not deduct trophies from you.
The trophies of your target do not affect how many trophies you stand to win.
An attacker has to gain at least 1 Star from attacking your village to start gaining trophies from you. The amount of trophies you lose is determined by how many Stars the attacker got and how much damage they were able to inflict.
Your attacker's trophies or your trophies at the time of the attack do not affect how many trophies you lose.