Ahmed Mohamed just wanted to impress his teachers with a homemade invention. The story of what happened next has made the 14-year-old from Irving, Tex., the object of national outrage and attention.

Eager to show off to his engineering teacher, Mohamed walked into MacArthur High School on Monday morning with his hastily assembled invention: a digital clock.

Hours later, the ninth-grader was escorted out of the school in police custody after teachers mistook the device for a bomb.

The incident has triggered allegations of racism and made a Texas school district the target of outrage that began online and quickly spilled into the most powerful offices in the land.

As the story spread, along with a photo of Mohamed in a NASA T-shirt and handcuffs, support came flooding in.

“Cool clock, Ahmed,” President Obama wrote in a tweet Wednesday. “Want to bring it to the White House? We should inspire more kids like you to like science. It’s what makes America great.”

Facebook founder Mark Zuckerberg extended an invitation to Mohamed to meet him at the social media giant’s California headquarters. #IStandWithAhmed trended on Twitter. NASA scientists and MIT researchers offered tours, along with praise for the teen’s ingenuity.

When he learned of Obama’s and Zuckerberg’s comments Wednesday, Mohamed grinned broadly, a lawyer for his family told The Washington Post.

“I’m the person who built a clock and got in a lot of trouble for it,” the jittery and smiling ninth-grader said during a news conference outside of his home on Wednesday after his arrest became national news.

Ahmed Mohamed, the Texas teenager who was arrested when his homemade clock was mistaken for a bomb, thanks supporters. (Reuters)

Mohamed said it felt “outstanding” to receive so much support. He said he hoped to attend MIT.

“I never thought it would get this far,” he added.

School officials, however, insist that their staff and police acted appropriately in investigating the device as a potential threat.

“The information that has been made public to this point has been very unbalanced,” Lesley Weaver, a spokeswoman for Irving Independent School District, said at a Wednesday news conference. “We always ask our students and staff to immediately report if they observe any suspicious items or if they observe any suspicious behavior.

“We will always take necessary precautions to protect our students and keep our school community as safe as possible. That is our priority.”

Irving Police Chief Larry Boyd said that Mohamed will not be charged with any wrongdoing and that the case has been closed.

“We have no evidence to support that there was an intention to create alarm or cause people to be concerned,” Boyd told reporters Wednesday.

Mohamed was suspended from school for three days.

Mohamed, a self-assured kid with thick-framed glasses and a serious expression, had just started at MacArthur High School a few weeks ago. He has a talent for tinkering — he constructs his own radios and once built a Bluetooth speaker as a gift for his friend — and he wanted to show his new teachers what he could do.

So on Sunday night, he quickly put together a homemade digital clock: “Just something small,” as he casually put it to the Dallas Morning News — a circuit board and power supply connected to a digital display. He proudly offered it to his engineering teacher the next day.

But the teacher looked wary.

“He was like, ‘That’s really nice,’ ” Mohamed told the newspaper. “ ‘I would advise you not to show any other teachers.’ ”

During English class, the clock beeped, annoying his teacher. When he brought the device up to her afterward, she told him “it looks like a bomb,” according to Mohamed.

“I told her, ‘It doesn’t look like a bomb to me,’ ” he told the Morning News.

But the English teacher kept the clock, and during sixth period, Mohamed was pulled out of class by a police officer and the principal, who, the teen said, urged him to sign a written statement or he would be expelled. They took him to a room where four other officers were waiting. When he entered, one officer leaned back in his chair and said, “That’s who I thought it was,” Mohamed told MSNBC.

“They interrogated me and searched through my stuff and took my tablet and my invention,” Mohamed said. “They were like, ‘So you tried to make a bomb?’ I told them no, I was trying to make a clock.”

But, he said, his questioner responded: “It looks like a movie bomb to me.”

Mohamed was taken to police headquarters, handcuffed and fingerprinted.

During questioning, officers repeatedly brought up his last name, Mohamed said. (His family is from Sudan and is Muslim.)

When he tried to call his father, Mohamed said he was told he couldn’t speak to his parents until after the interrogation was over. They asked if he had plastic explosives.

“I really don’t think it’s fair because I brought something to school that wasn’t a threat to anyone,” Mohamed told the Dallas-Fort Worth NBC affiliate. “I didn’t do anything wrong. I just showed my teachers something, and I end up being arrested later that day.”

Asked why Mohamed was not permitted to call his parents while being questioned by police, Boyd, the police chief, said he did “not have answers to your specific question.”

Boyd said officers believed the clock was “possibly the infrastructure for a bomb” and that when they arrived at the scene, they were not told that Mohamed had shown the device to his engineering teacher.

Mohamed immediately told officers that it was a clock, but Boyd said the teen did not initially say more about the device.

“It is what appears to be an electronic homemade device with wires running through it inside a metal case,” Boyd said. “It was not immediately clear that it was the experiment he said it was.”

Mohamed was eventually released to his parents.

Speaking to the Dallas Morning News from his Irving home, Ahmed’s father, Mohamed Elhassan Mohamed, blamed the incident on Islamophobia.

“He just wants to invent good things for mankind,” he said of his son. “But because his name is Mohamed and because of September 11th, I think my son got mistreated.”

That sentiment has rippled out in their community. Muram Ibrahim, a 15-year-old cousin of Mohamed’s who was part of his middle school robotics team, said Ahmed’s arrest makes her feel differently about going to school in Irving.

“It just shocked me that people could do this to him. He’s a 14-year-old boy, and he’s a genius,” she told The Post, recalling how her teammates used to call her younger cousin over whenever they needed help.

“I thought there’s a lot of diversity at Irving [Independent School District], and I thought that it was different from other school districts,” she said. “But I was wrong, and it makes me really sad that I’m wrong.”

The Council on American-Islamic Relations said it will be looking into the case.

“I think this wouldn’t even be a question if his name wasn’t Ahmed Mohamed,” Alia Salem, CAIR’s executive director for the Dallas-Fort Worth region, told WFAA.

Weaver, the schools spokeswoman, said the district would attempt to meet with the family Wednesday. And Boyd said police would also meet with the Mohameds.

For some, the situation was a blatant case of racial profiling that caused school officials to perceive a 14-year-old aspiring engineer as a threat. And given that public figures routinely pay lip service to the need to increase participation in Science, Technology, Engineering and Math fields — especially among minority students — Mohamed’s arrest was particularly offensive to scientists who see their curious, younger selves in the teen.

“I used to take circuit boards & electronics to school, even as the only brown kid,” wrote Anil Dash, a tech entrepreneur. “Now, my entire job is building a community of makers.”

Linda Moreno, an attorney with the Constitutional Law Center for Muslims in America, who is representing the family, said that Mohamed should be celebrated not arrested.

“He’s just a bright 14-year-old American-Muslim kid,” Moreno said. “All he did was a science project for his school. He made an alarm clock to impress his teachers.”

“He certainly didn’t expect to be detained, interrogated, handcuffed, booked, fingerprinted and arrested at the end of the school day,” she added.

But the school district and Irving officials remained steadfast in their belief that Mohamed’s arrest was a reasonable attempt to investigate a “potential threat.”

“As a parent, I agree that if this happened to my child I would be very upset,” Irving Mayor Beth Van Duyne said in a statement Wednesday. “It is my sincere desire that Irving ISD students are encouraged to use their creativity, develop innovations and explore their interests in a manner that fosters higher learning.

“Hopefully, we can all learn from this week’s events and the student, who has obvious gifts, will not feel at all discouraged from pursuing his talent in electronics and engineering.”

Ibrahim, Mohamed’s cousin, told The Post that she helped organize a protest at Irving schools, encouraging students to bring clocks in a show of solidarity.

Adam Goldman contributed to this report.