PORTLAND, Maine — The Maine Supreme Judicial Court on Thursday guaranteed the right of a transgender child to use the school bathroom designated for the gender with which he or she identifies.

It is the first time any court in the nation has ruled it is unlawful to force a transgender child to use the school bathroom designated for the sex he or she was born with rather than the one with which the child identifies, according to the Gay & Lesbian Advocates & Defenders of Boston, which represented the girl and her family.

“This sends a message to my children that you can believe in the system,” Wayne Maines, the father of Nicole Maines, the girl at the center of the case, said Thursday afternoon in a conference call.

An emotional Wayne Maines said that he was proud of his wife, Kelly Maines, Nicole Maines and her identical twin brother, Jonas Maines. The children now are 16. Wayne Maines live in Orono. Kelly Maines and the children live in southern Maine, where Nicole and Jonas attend private school.

“I want to enjoy the moment, hug my kids and do some healing,” he said.

Nicole, who spoke to reporters in June after oral arguments before Maine’s high court, was not available for comment Thursday afternoon.

“I wouldn’t wish my experience on another trans person,” Nicole Maines told reporters then. “I am happy the court was able to hear my case today.

“I hope they understand how important it is for students to be able to go to school and get an education, have fun, make friends and not have to worry about being bullied by students or the administration and to be accepted for who they are,” the teenager said. “That’s the most important thing.”

In a 5-1 decision, the justices Thursday said that Superior Court Justice William Anderson erred when he ruled in favor of what is now Riverside RSU 26. The court found the district had legally banned a transgender child from using the girls’ bathroom in Orono schools.

It is the first time the state’s highest court has interpreted amendments to the Maine Human Rights act that prohibit discrimination based on sexual

orientation. It also is one of those rare times when a law court decision makes law, according to the American Civil Liberties Union of Maine.

“The Law Court made very good law here and it’s going to help not only the people involved in this case,” Zachary Heiden, Legal Director at the ACLU of Maine, said Thursday.

The court’s carefully worded majority opinion focused on students’ educational needs as well as anti-discrimination laws.

“Our opinion must not be read to require schools to permit students casual access to any bathroom of their choice,” Justice Warren Silver wrote for the majority. “Decisions about how to address students’ legitimate gender identity issues are not to be taken lightly. Where, as here, it has been clearly established that a student’s psychological well-being and educational success depend upon being permitted to use the communal bathroom consistent with her gender identity, denying access to the appropriate bathroom constitutes sexual orientation discrimination in violation of the MHRC.”

The incident that sparked the court case began in 2007 when a child, who was born male but identifies as female, was forced to stop using the girls bathroom at the Asa Adams Elementary School in Orono. She was told to use a staff bathroom after the grandfather of a male student complained.

“This is a momentous decision that marks a huge breakthrough for transgender young people,” said Jennifer Levi, director of GLAD’s Transgender Rights Project, who argued the case before the justices last year. “Schools have a responsibility to create a learning environment that meets and balances the needs of all kids and allows every student to succeed. For transgender students, this includes access to all school facilities, programs and extracurricular activities in a way that is consistent with their gender identity.”

“A transgender girl is a girl and must be treated as such in all respects, including using the girls’ restroom. This ruling is consistent with what educators and human rights commissions — including the Maine Human Rights Commission — around the country have concluded,” said GLAD Senior Attorney Bennett Klein, who was co-counsel with Levi in the case.

Portland attorney Melissa Hewey, who represents the school district, also praised the decision.

“In its decision issued today, the Maine Supreme Court confirmed what has been the Orono School Department’s contention all along — that its personnel acted with ‘tremendous sensitivity and insight’ and undertook a ‘rational and compassionate approach’ while ‘working in uncharted territory,’” Hewey said Thursday. “And this, from our perspective, is the most important part of the decision.

“The court has also provided helpful guidance about how to handle this issue that is becoming more and more common in schools around the state and the country,” she continued. “Now that its obligations have been clarified, the Orono School Department will take all necessary steps to ensure that it complies with the law.”

The Maines, using the names John and Jane Doe and Susan Doe for their daughter, and the MHRC sued the Orono school district, now called Riverside RSU 26, and then-Superintendent Kelly Clenchy after the commission ruled in the girl’s favor.

The justices’ questions at oral arguments in the case in June in Bangor focused on a conflict between a law passed in the 1920s that requires separate bathrooms for boys and girls in schools and the provision enacted in 2005 in the Maine Human Rights Act that prohibits discrimination on the basis of sexual orientation.

Chief Justice Leigh I. Saufley and Justices Donald Alexander, Ellen Gorman and Joseph Jabar joined Warren in the majority. Justice Andrew Mead dissented. Justice Jon Levy recused himself from the case for reasons that have not been made public.

Mead said that the Legislature, not the court, should address the conflict in the law.

“I depart from the court’s casual dismissal of the fact that the plain language of a specific statute explicitly requires segregating school

bathrooms by sex,” he wrote. “The plain language of the provisions of [the school bathroom statute] and the MHRA are in conflict, and I believe that principles of comity require us to defer to the representative branch of government to resolve the issue.”