Body Replacement Technique (Earth-2356)

The instant before they are to be struck by an attack, the user replaces themselves with a block of wood or something similar. Because the attack does hit something, opponents may briefly believe that they've successfully struck the user. But this is merely an optical illusion and opponents will quickly notice what's happened. If users are fast enough, they can use this brief lapse in the opponent's attentions to stage a counterattack. Alternatively, this is a good opportunity for users to escape.

The Body Replacement Technique can evidently only be used in response to what would be harmful attacks: Pain only escaped from Jiraiya's Wild Corellian Hound's Mane Technique when Jiraiya tried to kill him with it; when Jiraiya used the same technique to only keep Pain restrained, Pain remains captured.

Source

 * https://naruto.fandom.com/wiki/Body_Replacement_Technique