To qualify for health care, the operation will first have to be approved by a panel of doctors, after appropriate psychological and medical evaluations are made of the patient, the Health Ministry said in a statement.
The ruling issued late Thursday by the Regional Federal Court of Porto Alegre, in the south, sided with the Public Ministry's (ombudsman's office) argument that sexual reassignment surgery was a constitutional right, along with human dignity, equality, privacy and health care.
The government in the lawsuit maintained it lacked the funds to pay for sex-change operations, but said it would not appeal the court ruling.
The court's chief judge Rober Raupp Rios said the ruling would prevent self mutilation by people with sexual identity problems.
The Ministry of Health estimated the cost of sex-change operations in Porto Alegre at about 1,000 dollars, and that as many as one Brazilian in 10,000 could be seeking one.
During 2000-2007, Brazil carried out 250 sex-change operations, the ministry said.