How did the Lord ‘put away’ the sin of David? 2 Samuel 12:13

And David said unto Nathan, I have sinned against the LORD. And Nathan said unto David, The LORD also hath put away thy sin; thou shalt not die. [2 Samuel 12:13 KJV] How, and when, did the Lord 'put away' David's sin?