FORT WORTH — A Texas judge ruled Friday that a Fort Worth hospital may not keep a brain-dead pregnant woman on life support against her family’s wishes, and ordered doctors to take her off the machines by 5 p.m. on Monday.

The ruling gives the family of the woman, Marlise Muñoz, their first legal victory in a two-month battle over the fate of her body that has raised an emotionally charged national debate over end-of-life care, abortion and a Texas law that prohibits medical officials from withdrawing life support from a pregnant patient.

The judge, R. H. Wallace Jr. of 96th District Court in Tarrant County, ruled that Ms. Muñoz, 33, who has been on life support at John Peter Smith Hospital since November and is now 22 weeks pregnant, was legally dead, agreeing with the family’s lawyers that the hospital had erred in its decision to keep her on life support. The hospital had said the Texas law addressing life support for pregnant women prevented it from granting the family’s wish, but the judge said the law did not apply to Ms. Muñoz because she is dead.

Judge Wallace set the 5 p.m. Monday deadline, saying he wanted to give the hospital time to file an appeal.