Where the story is told
This story comes from the Sunnah, not from the Quran. It is reported through several companions. Abu Hurayrah, may Allah be pleased with him, narrated it in Sahih al-Bukhari 3481 and Sahih Muslim 2756a. Abu Said al-Khudri, may Allah be pleased with him, narrated it in Sahih al-Bukhari 3478. Hudhayfah, may Allah be pleased with him, narrated it in Sahih al-Bukhari 6480.
The wording differs in some details, as shown below, but all the reports agree on the main events and on the man's answer to Allah.