sich zur Wehr setzen
to defend oneself
To actively defend oneself or resist an attack or injustice.
Als er beschuldigt wurde, setzte er sich sofort zur Wehr.
When he was accused, he immediately defended himself.

defense / weir
Loading your saved state.
to defend oneself
To actively defend oneself or resist an attack or injustice.
Als er beschuldigt wurde, setzte er sich sofort zur Wehr.
When he was accused, he immediately defended himself.

'Die Wehr' is closely related to the verb 'sich wehren' (to defend oneself). The basic meaning of protection and resistance is also found in words like 'Abwehr' (defense) or 'Bundeswehr' (German armed forces).
Die Dorfbewohner mussten sich gegen die Angreifer wehren.
The villagers had to defend themselves against the attackers.
The expression 'sich zur Wehr setzen' (to defend oneself / to resist) is a fixed unit with a reflexive pronoun. It is often followed by the preposition 'gegen' with the accusative to name the opponent or injustice.
Die Mitarbeiter setzten sich gegen die ungerechte Behandlung zur Wehr.
The employees defended themselves against the unfair treatment.
You can recognize the meaning of 'Wehr' from the context. If it is about defense, the expression 'sich zur Wehr setzen' is a signal. With rivers and water, it refers to the weir. In the context of fires and emergencies, it means the fire brigade.
Das Wehr reguliert den Wasserstand des Flusses.
The weir regulates the water level of the river.
The use of 'die Wehr' for 'die Feuerwehr' (the fire brigade) is a colloquial abbreviation. It is especially common in the combination 'die Freiwillige Wehr' (the volunteer fire brigade) in rural areas.
Mein Onkel ist seit 20 Jahren bei der Freiwilligen Wehr.
My uncle has been in the volunteer fire brigade for 20 years.
attack
'der Angriff' and 'sich zur Wehr setzen' form a clear contrast between attacking and defending. An attack comes from the side that actively moves against someone. Someone who 'sich zur Wehr setzt' reacts to this and defends themselves or offers resistance. Important: in this meaning, 'die Wehr' almost always appears in the fixed phrase 'sich zur Wehr setzen' (to defend oneself). So you do not simply say 'eine Wehr machen' when you mean defense.

Als der Mann sie bedrohte, setzte sie sich laut zur Wehr.
When the man threatened her, she loudly defended herself.
Der Angriff kam so plötzlich, dass niemand sofort reagieren konnte.
The attack came so suddenly that no one could react right away.