Before God created everything, He devised a plan for redeeming humanity.
GOD knows everything, including the future.
Before GOD created the heavens and the earth, He foreknew that evil would arise, that creation would rebel against Him, and that a solution would be necessary to save a remnant of people who would choose to love Him.
The apostle Paul referred to this plan as GOD's "eternal purpose."
10 His intent was that now, through the church, the manifold wisdom of God should be made known to the rulers and authorities in the heavenly realms, 11 according to his eternal purpose that he accomplished in Christ Jesus our Lord.
(Ephesians 3:10-11 NIV)
Peter wrote in 1 Peter 1:20 that Jesus was chosen before creation. And the Hebrews writer said in Hebrews 4:3 that GOD's works were finished before creation.
3 For we who have believed enter that rest, just as He has said,
“As I swore in My anger,
They certainly shall not enter My rest,”
although His works were finished from the foundation of the world.
(Hebrews 4:3 NASB)
This means that every event that occurred in history, is happening now, and will happen in the future was foreknown by GOD. And because of His foreknowledge, GOD was able to ensure that the events occurred such that the necessary outcome of the salvation of a remnant of humanity became a reality.