BANGOR, Maine — A pregnant, HIV-positive African woman will give birth in a Portland hospital rather than a federal prison after a U.S. District judge on Monday ordered that she be released on personal recognizance bail while her appeal to the 1st U.S. Circuit Court of Appeals is pending in Boston.

U.S. District Judge John Woodcock last month sentenced Quinta Layin Tuleh, 28, of Cameroon to 238 days in prison — twice as long as the recommended sentence of 114 days — for having false documents.

Tuleh did not address Woodcock during the hour-long hearing. But she appeared to be elated as she left the Margaret Chase Smith Federal Building with her attorney, Matthew Erickson of Bangor, and Jennifer Putnam, director of clinical services at the Frannie Peabody Center in Portland.

The mother-to-be declined to speak to a reporter and hid from a photographer behind a pillar after her picture was snapped.

“We’re delighted by the judge’s decision,” Erickson said outside the building. “It was very thoughtful and well thought out.”

Tuleh, whose due date is Aug. 29, agreed Monday to remain in Portland while on bail and receive treatment coordinated through the Frannie Peabody Center. The center offers support to people diagnosed with AIDS and the virus that causes the disease.

If the judge had denied the motion, Tuleh would have been transferred to the Federal Medical Center Carswell in Fort Worth, Texas, at the end of the week, according to the U.S. Marshal Service in Bangor. The facility provides specialized medical and mental health services to female offenders, according to information on the U.S. Bureau of Prisons’ Web site.

In imposing the sentence on May 14, Woodcock rejected a 114-day, or time-served, sentence recommended by her attorney and the federal prosecutor, according to a transcript of the hearing. The judge also imposed a sentence that was longer than the zero to six months recommended in the federal sentencing guidelines.

The judge said that to ensure Tuleh received proper medical care through the birth of her child and to increase its chances of being born free of the HIV virus, which causes AIDS, he was sentencing her to remain in jail until two weeks past her due date. Woodcock also said he was concerned that Tuleh would be deported to Cameroon before giving birth if she were to be released earlier.

Testimony on Monday from Putnam and an agent with U.S. Immigration and Customs Enforcement allayed those concerns, Woodcock said in granting the motion for bail.

“I recognize that the sentence turned out to be controversial,” he said. “I can certainly understand how some have misinterpreted what the court intended to do in this case.”

Woodcock said that what he had wanted to do was “to step in between the prison system and the social [safety] net” to ensure that Tuleh remained healthy and that the child was born healthy.

“At the time of the sentencing, I had no clear understanding of what the community could do,” Woodcock said. “I had no specifics.”

He got them Monday from Putnam, who testified that Tuleh would be put up in a Portland motel until housing in the city could be found for her. The pregnant woman already has been connected with an obstetrician, virologist and pediatrician for treatment, she said.

Her housing, food, medicine and treatment would be paid for by state and federal programs, Putnam said. Tuleh would be assigned a case manager at the center and would be eligible to be visited two or three times a week by a public health nurse. Used furniture and clothing are donated to the center and would be available to Tuleh, Putnam told the judge.

Patrick Mullen, an ICE agent in Portland, testified that removal proceedings against Tuleh would not begin until after her appeal was completed. Once that happened, she would not be taken into custody but would be given a date for a removal hearing in U.S. Immigration Court in Boston.

By staying in Portland, Tuleh also would be close to Zachary Heiden, the Maine Civil Liberties Union attorney who is handling her appeal, and the Immigrant Legal Advocacy Project, which is handling her application to remain in the U.S.

Tuleh is in the process of applying for asylum in the U.S., according to court documents, on the basis that she is the victim of a crime. She may have suffered abuse while working for her former employer, who has not been named, in Aroostook County, according to an affidavit filed by her immigration attorney.

The African woman arrived in the U.S. in September and lived in Maryland until early January, when she went to Presque Isle to work as a nanny for a family, according to court documents. She was arrested Jan. 21 at the Presque Isle Airport after false documents were discovered in her luggage. She told investigators that she had quit her job in a dispute with the woman for whom she worked.

Tuleh became pregnant before she came to Maine, Erickson has said, but did not confirm the pregnancy until after her arrest. Her HIV status was not known until a few days before her sentencing on May 14, according to Erickson.

A three-judge panel in Boston has agreed to hear the appeal on an expedited schedule, but oral arguments are not expected to be held until late July and early August. In addition to appeals filed by the prosecution and the defense, a group of 15 individuals and organizations have filed in Bangor and Boston a “friend of the court” brief in support of Tuleh.

Woodcock said Monday that he found the brief “articulate and helpful” in making his decision about whether to release Tuleh on bail.