The lawsuit alleged he would avoid using the toilet altogether to avoid being punished and suffered severe depression and anxiety as a result.

1:34

Video:October: Meet the first transgender playmate

The student also claimed the school initially denied him from running for junior prom king and allocated him to a room by himself during a week-long orchestra camp.

The Kenosha Unified School Board voted on Tuesday to settle the lawsuit because its legal costs were mounting, even though it continued to deny the allegations.

It had been attempting to get the US Supreme Court to overturn previous court rulings which allowed Mr Whitaker, who was born a girl, to use the male facilities.

Mr Whitaker has since left the school and gone to university but the settlement allows him to use the male facilities if he returns as an alumnus or community member.

2:46

Video:Oct: School uniform policy causes transgender row

After the school board's vote, the student, who graduated from Tremper in June, expressed his relief.

In a statement, released by the Transgender Law Centre, he said: "I am deeply relieved that this long, traumatic part of my life is finally over and I can focus on my future and simply being a college student.

"Winning this case was so empowering and made me feel like I can actually do something to help other trans youth live authentically.

"My message to other trans kids is to respect themselves and accept themselves and love themselves. If someone’s telling you that you don’t deserve that, prove them wrong."

Mr Whitaker is currently a freshman at the University of Wisconsin-Madison and plans to major in biomedical engineering.

2:01

Video:July: Reaction to Trump's transgender tweets

Joseph Wardenski of civil rights law firm Relman, Dane & Colfax, which represented the student in the latest lawsuit, said the settlement sent a "clear message" to all school districts.

He added: "Discriminating against transgender students is against the law and harms students who simply want to go to school."

Ronald Stadler of Mallery & Zimmerman, which represented Kenosha Unified School District (KUSD) said mounting legal costs led them to settle.

He said in a statement: "KUSD has maintained all along that Whitaker was being treated entirely consistent with a procedure that, at the time the decision was made, was entirely legal under the law."