A woman who has a child with accused Chelsea bomber Ahmad Khan Rahami won an order from a New Jersey judge giving her sole legal and physical custody of the child, and prohibiting Rahami from contacting the child until a Sept. 27 hearing.

Maria Mena’s claim that Rahami’s apparent involvement in terrorism and attempted murder of police officers could cause harm to the child that “is both emergent and irreparable,” according to the order by Superior Court Judge Peter Barnes III.

Rahami, 28, a U.S. citizen born in Afghanistan, remains in a Newark hospital after he was captured during a shootout with police in Linden, New Jersey, on Monday.

The New Brunswick judge denied Mena’s request to change the child’s last name, but permitted her to renew the request later after presenting evidence.

Barnes also denied Mena’s request to order counseling for the child and to prohibit news reporters from contacting the child, noting he had no authority to do either.

“However, the court recommends that the plaintiff obtain counseling services for the … child on her own,” Barnes wrote in his order.

Mena, of Edison, New Jersey, had not seen Rahami, of Elizabeth, New Jersey, in person for two years and had not talked to him since January, the documents state. She said she suddenly saw him again on Monday — on television news broadcasts — wounded and bleeding from police bullets as the suspect in bombings in Chelsea and New Jersey.

Rahami had a history of conflict with Mena and was constantly in arrears on child support, according to court papers.

Other Superior Court papers show that Rahami had long been accused of failing to pay child support to Mena. In 2015, for instance, court papers indicated he was $3,546 in arrears. At one point, in 2008, a judge ordered that Rahami’s wages be garnished to pay the support.

Other papers discussed parenting time each parent would receive with the child, with Mena assigned Christmas and Thanksgiving and Rahami assigned the Muslim holy days of Eid al-Fitr and Eid al-Adha.

In 2012, the parents were ordered not to take the child out of the state or the country without the permission of the other parent or the court.

In a court ruling in 2011, Mena’s request to deny overnight parenting to Rahami was rejected, with the judge saying there was no evidence supporting Mena’s claim that the child was in danger of being removed from the country.

On Wednesday morning, four people, escorted by two officers, came to the quiet Edison home where Mena lives and spoke to someone through the window. They assured the person they were not media and spoke in Spanish, leaving shortly after.

With Alison Fox