A federal judge in Manhattan ordered a “compassionate release” on Tuesday for Lynne F. Stewart, the former defense lawyer convicted of assisting terrorism who is dying from cancer in a federal prison in Texas.

Ms. Stewart, 74, who was convicted in 2005, sought release in 2013 under a Bureau of Prisons program for terminally ill inmates, but did so without the bureau’s support. The judge, John G. Koeltl of United States District Court, rejected the request in August, but indicated that he would look favorably upon such action if the Bureau of Prisons itself made such a motion.

The request to Judge Koeltl on Tuesday came from the director of the Bureau of Prisons through the office of Preet Bharara, the United States attorney for the Southern District of New York. The filing said Ms. Stewart qualified for compassionate release because she had a diagnosis of a terminal, incurable illness with a life expectancy of less than 18 months and because of the relatively limited risk of recidivism and danger to the community if she were released.

“The defendant’s terminal medical condition and very limited life expectancy constitute extraordinary and compelling reasons that warrant the requested reduction” in sentence to time served, the judge’s order said.

Ms. Stewart is to live with her son, a lawyer, in Brooklyn.

Ms. Stewart is best known for her defense of Sheikh Omar Abdel Rahman, the blind Egyptian cleric who was convicted in 1995 of conspiring to blow up landmarks in New York City. She was later tried and convicted of smuggling messages from Mr. Abdel Rahman in prison to his violent followers in Egypt, and was sentenced to 10 years in prison. She has been serving her sentence at the Federal Medical Center Carswell, in Fort Worth.

Ms. Stewart was found in 2005 to have breast cancer; in 2012, doctors determined that her cancer had spread to her lungs, lymph system and bones, a court filing shows.

Her lawyer, Jill R. Shellow, said earlier on Tuesday, before the judge’s ruling, that she had informed her client of the government’s request, and that Ms. Stewart was looking forward to being with her family.

“It restores my faith in the Justice Department to do the right thing,” Ms. Shellow said. Later, after Judge Koeltl issued his order, Ms. Shellow added, “The judge’s exercise of mercy on New Year’s Eve shows his compassion for Lynne and the depth of his commitment to seeing that justice is done.”

Ms. Stewart, in a 12-page handwritten letter to the judge during the summer, said she did not want to die in prison, “a strange and loveless place,” as she put it. “I want to be where all is familiar — in a word, home.”

Judge Koeltl’s order says that Ms. Stewart shall be released “as soon as her medical condition permits, the release plan is implemented, and travel arrangements can be made.”

Ms. Shellow said Ms. Stewart could be released as early Tuesday night, and would be met by her husband.