Afflict is a triggered ability that triggers when the afflicted creature becomes blocked (CR 702.130a). This trigger goes on the stack during the declare blockers step, well before the combat damage step. It does not depend on whether the attacking creature survives to deal damage.
Because the trigger resolves in the declare blockers step (or at the next time players receive priority after blockers are declared), the defending player loses life from afflict before combat damage is even assigned. By the time combat damage is dealt and the blocking creature might kill the attacker, the afflict loss has already happened.
This means that even if the blocking creature has deathtouch, first strike, or enough power to destroy the attacker outright, the afflict life loss still occurs. There is no way to "prevent" afflict by killing the attacker during combat damage (CR 509.2, 702.130a).
Example: You attack with a 2/2 creature with Afflict 2. Your opponent blocks with a 5/5. At the end of the declare blockers step, Afflict 2 triggers and resolves — your opponent loses 2 life. Then in the combat damage step, the 5/5 deals 5 damage to your 2/2, killing it. Your opponent still lost the 2 life from Afflict regardless.
Note that if the attacking creature is removed before blockers are declared (so it never becomes blocked), Afflict never triggers at all, since the trigger condition is never met (CR 702.130a).
Unofficial fan resource — not affiliated with or endorsed by Wizards of the Coast. Answers are AI-generated estimates grounded in the Comprehensive Rules and are not a substitute for an official judge. Verify anything match-critical.