He was arrested and detained for hours because police thought he was involved in the deadly shooting at a Quebec City mosque Sunday night.

It turned out that Mohamed Belkhadir, an engineering student at Laval University, was just a witness to the attack that left six people dead — men he called his brothers — and 19 others injured.

Like the victims, Belkhadir was at the mosque for evening prayers. He had left the building and was clearing snow off the stairs outside when he heard the gunshots.

His instinct was to hide. When the noises stopped, he called 911 and then went inside the mosque to see if anyone was still alive.

"I found someone near the door," he told Radio-Canada. "I didn't know if he was dead or not. I saw another person who was breathing, and I gave him my coat. As I was doing that, I saw a person carrying a weapon."

Quebec provincial and municipal police officers stand guard after a shooting at the Quebec City Islamic cultural centre on Jan. 30, 2017. (Andre Pichette/EPA)

Belkhadir thought it was the gunman, so he ran. He didn't know the person coming toward him was actually a police officer.

Police ordered him to get down on the ground, and that's when he realized what was going on.​

No rancour on his part

Not long after police apprehended Belkhadir, they arrested another man who they say called 911 to talk about his role in the shooting. Both men spent the night in jail.

In the meantime, rumours swirled about their identities. Their names were eventually confirmed as Belkhadir and Alexandre Bissonnette.

CBC News, based on police sources, was among the news outlets that decided to publish the names of the two suspects the morning after the shooting.

Friends defended Belkhadir, saying it was coincidence he was at the mosque at the time of the shooting, he was a good guy and isn't a violent person.

It turns out they were right; he hadn't been involved.

At that point, media around the world had widely reported that there were two shooters.

On Tuesday, the Prime Minister's Office contacted Fox News, asking it to retract or correct a tweet containing false information about the identity of the shooter that had been up for around 24 hours.

"The suspect was identified as a 27-year-old French-Canadian — not someone of Moroccan origin," wrote Kate Purchase, the PMO's director of communications.

"To paint terrorists with a broad brush that extends to all Muslims is not just ignorant — it is irresponsible."

The Fox News tweet has since been taken down.

Belkhadir released

It was shortly after noon on Monday that Quebec provincial police said in a tweet only one of the people arrested was a suspect — and the other was an important witness to the violence.

La SQ confirme qu’un seul des individus arrêté hier soir en lien avec l’<a href="https://twitter.com/hashtag/attentat?src=hash">#attentat</a> de <a href="https://twitter.com/hashtag/Qu%C3%A9bec?src=hash">#Québec</a> est considéré comme suspect. —@sureteduquebec

Belkhadir was released.

CBC immediately removed the names of both Belkhadir and Bissonnette, until it could be ascertained which of the men who were arrested was the lone suspect.

Later Monday, Bissonnette was charged with six counts of first-degree murder and five counts of attempted murder while using a restricted firearm.

<a href="https://twitter.com/hashtag/Attentat?src=hash">#Attentat</a> de <a href="https://twitter.com/hashtag/Quebec?src=hash">#Quebec</a> Suite à l’enquête, l’autre individu est maintenant considéré comme témoin. —@sureteduquebec

Despite everything that happened to him, Belkhadir says he isn't holding a grudge against the police.

"They were very nice to me," he said.