David's census makes him a Pharaoh but he doesn't end like Pharoah. It's not exactly because he offers sacrifice (21:26). By the time he does that, the Lord has already relented (21:15). The chapter's structure makes it clear that the Lord's mercy is the turning point. The story is told in three sections: The census (vv. 1–6); the plague (vv. 7–15); and the sacrifice (vv. 16–27). The latter two sections are chiastically arranged. Verses 7–15 moves from Yahweh's anger with David to His compassion:

A. David's act is evil in the sight of God; so He strikes Israel, v. 7

B. David confesses his sin, v. 8

C. Lord speaks through Gad: choose your discipline, vv. 9–12

B'. David confesses Lord’s mercy, v 13

A'. Lord strikes with pestilence, but relents, v 15

Verses 16-27 describe David's purchase of Ornan's threshing floor and the offering of sacrifice:

A. Angel with sword, v. 16

B. David worships and confesses sin, 17

C. Angel speaks to David through Gad: build altar, v. 18

D. Negotiations for threshing floor, vv. 19–25

C'. David builds altar and lays offering on it, v. 26a

B'. David call on the name of Yahweh, who answers with fire, v. 26b

A'. Angel sheaths sword, v. 27

One small note on this latter structure: It might appear from C/C' that David doesn't strictly obey the Lord's command. He is told to build an altar, but he builds an altar and offers ascensions and peace offerings. The structure suggests, though, a command-compliance relationship, and makes it clear that nothing is turned to smoke until the Lord's stokes up the altar. “Offer” in verses 26a does not mean “turn to smoke”; like Elijah on Carmel, David builds an altar and prepares a sacrifice, but waits for Yahweh to complete the sacrifice with fire from heaven.

The more important point is that the structure of the story as a whole places the Lord's mercy in the center: Sin leads to a plague; the Lord relents; and then David offers sacrifice, and the angel sheaths the sword. The Lord shows mercy before sacrifice, though the angel puts away his weapon only after sacrifice. The sacrifice is necessary. It makes the angel's pause permanent. But the Lord paused before the sacrifice.

The turning point for David, the saving grace that keeps him from being destroyed like Pharaoh, is the Lord's sorrow over the calamity Israel suffers. That sorrow leaves a space open for sacrifice.

God sends calamity; God sorrows over calamity. Jesus condemns Jerusalem; Jesus laments over Jerusalem. In that sorrowful divine lament is the hope of Israel and the hope of the world. In that space we have opportunity to offer sacrifice of repentance.