NEW YORK – Calling himself a Muslim soldier, a defiant Pakistan-born U.S. citizen pleaded guilty Monday to carrying out the failed Times Square car bombing and left a sinister warning that unless the United States leaves Muslim lands alone, “we will be attacking U.S.”

Faisal Shahzad entered the plea in U.S. District Court in Manhattan just days after a federal grand jury indicted him on 10 terrorism and weapons counts, some of which carry mandatory life sentences. He pleaded guilty to them all.

Widely circulated snapshots of Shahzad — a U.S.-trained financial analyst and married father of two — show him with a neatly trimmed beard, all smiles and looking carefree behind sunglasses or with his American wife. When led into court Monday, he had on a white skullcap and prisoner’s uniform, his beard shaggy and his demeanor serious.

U.S. District Judge Miriam Goldman Cedarbaum challenged Shahzad repeatedly with questions such as whether he looked at the people in Times Square, especially the children, to see who they were or whether he really built the bomb by himself. He repeatedly insisted he acted without help from others in the United States and built the bomb “all by myself.”

“One has to understand where I’m coming from,” Shahzad said calmly. “I consider myself a Muslim soldier.”

The 30-year-old described his effort to set off a bomb in an SUV that he parked in Times Square on May 1, saying he chose the warm Saturday night because it would be crowded with people he could injure or kill. He said he conspired with the Pakistan Taliban, which provided more than $15,000 to fund his operation and five days of explosives training late last year and early this year, just months after he became a U.S. citizen.

A Maine man and two others from Massachusetts suspected of supplying money to Shahzad have been detained on immigration charges; one was recently transferred to New York.

Mohammad Shafiq Rahman of South Portland is in federal custody in Portland awaiting a hearing on the immigration charges. That hearing is now scheduled for Wednesday.

His attorney, Cynthia Arn, has said that she doesn’t expect any criminal charges to be filed against Rahman, and that she hopes a judge will order him to be released on bond at Wednesday’s hearing.

Federal authorities have said that Rahman and Aftab Khan, 27, and Pir Khan, 43, both of Watertown, Mass., may have helped fund Shahzad through an informal money transfer network. But the men may not have known how the money was going to be used, authorities said.

Rahman, a computer expert, came to the United States on a work visa in 1999 and has been in the country illegally since 2006, when his request for an extension was denied. Since his arrest on May 13, Rahman has been in federal custody in the Cumberland County Jail in Portland.

In court Monday, Shahzad explained that he packed his vehicle with three separate bomb components, hoping to set off a fertilizer-fueled bomb packed in a gun cabinet, a set of propane tanks and gas canisters rigged with fireworks to explode into a fireball. He also revealed he was carrying a folding assault rifle for “self-defense.”

Shahzad said he lit a fuse and waited 2½ to five minutes for the bomb to erupt.

“I was waiting to hear a sound but I didn’t hear a sound. So I walked to Grand Central and went home,” he said.

The judge repeatedly interrupted Shahzad, including when he said his plot was to retaliate against the United States and the forces of up to 50 other countries that had “attacked the Muslim lands.”

Cedarbaum said: “But not the people who were walking in Times Square that night. Did you look around to see who they were?”

“Well, the people select the government,” Shahzad said. “We consider them all the same. The drones, when they hit “

Cedarbaum interrupted again: “Including the children?”

Shahzad answered: “Well, the drone hits in Afghanistan and Iraq, they don’t see children, they don’t see anybody. They kill women, children, they kill everybody. It’s a war, and in war, they kill people. They’re killing all Muslims.”

Later, he added: “I am part of the answer to the U.S. terrorizing the Muslim nations and the Muslim people. And, on behalf of that, I’m avenging the attack. Living in the United States, Americans only care about their own people, but they don’t care about the people elsewhere in the world when they die.”

Cedarbaum asked him if he understood that some charges carried mandatory life sentences and that he might spend the rest of his life in prison. He said he did.

At one point, she asked him if he was sure he wanted to plead guilty.

Shahzad said he wanted “to plead guilty and 100 times more” to let the United States know that if it did not get out of Iraq and Afghanistan, halt drone attacks and stop meddling in Muslim lands, “we will be attacking U.S.”

Sentencing was scheduled for Oct. 5.

The Bridgeport, Conn., resident was arrested trying to leave the country May 3, two days after the bomb failed to ignite near a Broadway theater.

Authorities said Shahzad immediately cooperated, delaying his initial court appearance for two weeks as he spilled details of a plot meant to sow terror in the world-famous Times Square when it was packed with thousands of potential victims.

The bomb apparently sputtered, emitting smoke that attracted the attention of an alert street vendor who notified police, setting in motion a rapid evacuation of blocks of a city still healing from the shock of the September 2001 terrorist attack on the World Trade Center.

According to the indictment issued last week, Shahzad received a total of $12,000 before the attack from the Pakistani Taliban through cash drop-offs in Massachusetts and New York.

Attorney General Eric Holder said after the plea: “Faisal Shahzad plotted and launched an attack that could have led to serious loss of life, and today the American criminal justice system ensured that he will pay the price for his actions.”

Shahzad was accused in the indictment of receiving explosives training in Waziristan, Pakistan, during a five-week trip there. He returned to the United States in February.

Pakistan has arrested at least 11 people since the attempted attack. An intelligence official has alleged two of them played a role in the plot. No one has been charged.