Mr. Grimm, the brief said, “avoids drinking liquids and tries not to urinate during the school day” and has, as a consequence, “developed painful urinary tract infections and felt distracted and uncomfortable in class.”

In a statement issued on Friday, Mr. Grimm said: “I never thought that my restroom use would ever turn into any kind of national debate. The only thing I ever asked for was the right to be treated like everyone else.”

He continued: “While I’m disappointed that I will have to spend my final school year being singled out and treated differently from every other guy, I will do everything I can to make sure that other transgender students don’t have to go through the same experience.”

Speaking of the Supreme Court’s decision, Shannon Minter, the legal director of the National Center for Lesbian Rights, said: “This is one of the most important days in the history of the transgender movement. The outcome of this case is likely to shape the future of that movement in ways that will resonate for a very long time.”

Gary McCaleb, a lawyer with Alliance Defending Freedom, which filed a brief supporting the school board in Virginia, said, “Schools have a duty to protect the privacy and safety of all students.”

“In light of the right to bodily privacy, federal law should not be twisted to require that a male be given access to the girls’ facilities, or a female to the boys’ facilities,” he said.

After Mr. Grimm challenged the school board’s bathroom policy in court last year, a divided panel of the United States Court of Appeals for the Fourth Circuit, in Richmond, Va., ruled the policy unlawful. A trial judge then ordered school officials to let Mr. Grimm use the boys’ bathroom.