HOUSTON — Ahmed Mohamed’s homemade alarm clock got him suspended from his suburban Dallas high school and detained and handcuffed by police officers on Monday after school officials accused him of making a fake bomb. By Wednesday, it had brought him an invitation to the White House, support from Hillary Rodham Clinton and Mark Zuckerberg, and a moment of head-spinning attention as questions arose whether he had been targeted because of his name and his religion.

As a result, a 14-year-old freshman at MacArthur High School in Irving, Tex., who is partial to tinkering, technology and NASA T-shirts and wants to go to M.I.T., found himself in a social media whirlwind that reflected the nation’s charged debates on Islam, immigration and ethnicity.

“Cool clock, Ahmed,” President Obama said on Twitter. “Want to bring it to the White House? We should inspire more kids like you to like science. It’s what makes America great.” Mr. Obama’s staff invited Ahmed to the White House for Astronomy Night on Oct. 19, an event bringing together scientists, engineers, astronauts, teachers and students to spend a night stargazing from the South Lawn.

The president’s spokesman said the episode was a case study in unreasoned prejudice in an era when the country is fighting Islamic terrorism at home and in the Middle East.