Afflict is a triggered ability that triggers when the creature with afflict becomes blocked (CR 702.130a). At that moment — during the declare blockers step — the trigger is placed on the stack. It does not care what happens to the blocking creature afterward.
Once a creature is declared as a blocker, the attacking creature is considered "blocked" for the rest of combat (CR 509.1h). Even if the blocking creature is then removed by a spell or ability (killed, bounced, exiled, etc.), the attacking creature remains blocked and the afflict trigger has already been created and will resolve normally.
The afflict trigger causes the defending player to lose life equal to the afflict value (CR 702.130a). This life loss is completely independent of combat damage, so it resolves during the declare blockers step or shortly after — long before the combat damage step.
Concrete example: You attack with a creature that has Afflict 2. Your opponent blocks it with a 2/2. In response to the afflict trigger, your opponent casts Giant Growth on their blocker — or you cast Lightning Bolt to kill the blocker. It doesn't matter: the afflict trigger is already on the stack and will resolve, causing the defending player to lose 2 life regardless.
Note: If somehow the attacking creature itself leaves the battlefield before the trigger resolves, the trigger still resolves because afflict does not require the source to still be on the battlefield (CR 603.4). The defending player still loses the life.
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.