‘Allah has created, but who created Allah?’ Whoever experiences any such thought should say, ‘I believe in Allah.’”
Another wording states:
“Satan comes to one of you and asks, ‘Who created the heaven? Who created the earth?’ He replies, ‘Allah.’” The report adds: “Let him say, ‘I believe in Allah and His messengers.’”
Another wording says:
“‘Who created this? Who created that?’—until he says, ‘Who created your Lord?’ When he reaches that point, let him seek refuge in Allah and stop pursuing it.”
This is al-Bukhārī’s wording, or something close to it.
In Muslim, Anas reported that the Prophet—may Allah bless him and grant him peace—said:
“Allah, mighty and majestic, said: ‘Your community will keep asking, “What is this? What is that?” until they say, “Allah created creation, but who created Allah—glorified is He?”’”
In al-Bukhārī, Anas said:
“The Messenger of Allah—may Allah bless him and grant him peace—said: ‘People will never cease asking one another: Allah is the Creator of everything, but who created Allah?’”