Individual school districts in places like California and Illinois have adopted rules barring transgender students from restrooms that correspond with their gender identity. Federal officials have intervened and threatened to cut off Title IX funds to districts that do not allow transgender students to use their preferred bathrooms and changing areas, though some conservatives have questioned the government’s interpretation of that rule.

The South Dakota legislation would seem to put the state in conflict with the Obama administration’s interpretation of the federal Title IX law, which prohibits discrimination on the basis of sex in any education program or activity that receives federal funds. Mr. Lewis said last week that he would probably continue to use the men’s restroom at school even if Mr. Daugaard signed the bill. Even supporters of the legislation acknowledge that a school district will probably be sued if it becomes law.

“This bill would put schools in a very difficult situation, where they have to decide whether they want to comply with federal law or they’re going to follow what their state is mandating,” said Heather Smith, executive director of the American Civil Liberties Union of South Dakota, which opposes the bill.

Mr. Deutsch, the bill’s sponsor, said he was unaware of major disputes over transgender bathroom access in his state and acknowledged that the bill was “entirely preventative.” But he suggested that not enacting it could also lead to lawsuits, and that “in a small, rural state like this, there’d be an outrage from students” if a transgender youth were given full access to showering and changing facilities.

The bill has support from the Heritage Foundation, the Washington-based conservative research group, and the Roman Catholic bishops of South Dakota.

“The teaching of the Catholic Church is clear: One’s gender, male or female, is determined by God and not a matter of personal choice,” the bishops said in a statement last month. They added that the bill would respect “the innate dignity of all persons in our schools.”

Mr. Deutsch said he felt “terrible that transgender children feel under siege,” and noted that his bill would allow transgender students to request a separate accommodation if they did not want to use the bathroom corresponding with their sex at birth.