You refused to turn to Him but He still loved you. So He created a hardship which made you turn to Him. The Prophet ﷺ said: “If Allah wants to do good to somebody, He afflicts him with trials.” [Al-Bukhari]