ISLAMABAD - Nadir Soofi, a gunman shot dead after opening fire at a Texas exhibit of caricatures of the Prophet Mohammad, was a popular schoolboy in Pakistan but struggled to adjust to the United States after moving there as a teen, friends said on Tuesday.

Soofi's story appeared to trace a familiar arc for some Western Islamists - disappointment, alienation, and a search for belonging that ended with the embrace of militancy.

That is what police say inspired Soofi and his roommate, Elton Simpson, to attack the exhibit and contest to draw Prophet Mohammad cartoons on Sunday.

Such depictions are offensive to Muslims and often spark violence. Event organizers said the event was defending free speech.

The two gunmen were shot dead by a police officer before they could kill anyone.

Friends in Pakistan, who studied with Soofi at the elite International School of Islamabad, were stunned to discover that police had identified him as was one of the attackers.

"When he was in Islamabad, he had a great life. His mom was an American who taught art at the school, he was in plays, popular with girls," said one of Soofi's best friends at school.

"His nickname was Goofy" because of his sense of humor, said the man, who declined to be identified to preserve his privacy.

Another classmate said Soofi played the lead in the school's production of the play "Bye Bye Birdie".

"He was a popular kid, the opposite of a radical extremist," she said.

Soofi's parents divorced around the time he was in tenth grade, the friend said, and he moved to Utah with his mother.

Over the years, Soofi told his old friends he did not fit in and had many disappointments.

He went to dental school, but said he had to drop out because of financial problems, the male friend said.

He tried and failed at various ventures including a dry cleaning store, he said.

He told friends he had a child with a Bosnian woman but the relationship did not work out.

"He said 'life is really tough here'," the male friend said. "Alienation, an identity crisis, whatever you want to call it, he was kind of alone."

"I guess the one thing he could identify with was religion."

In the past few years, Soofi grew a beard and only posted pictures of himself wearing sunglasses on Facebook, the friend said. Old friends teased him for that but also began to worry, the friend said.

Gradually they lost contact.

"I looked at his pictures, and I didn't recognize him," the friend said. "I don't know what happened to him in America."