The social media and rocket companies are headquartered in California, which the billionaire criticized for its recent transgender legislation.

Elon Musk said on Tuesday that he would move the headquarters of two of his businesses, the social media platform X and the rocket manufacturer SpaceX, from California to Texas in protest against a new law designed to protect transgender children.

The California law, signed on Monday by Gov. Gavin Newsom, a Democrat, bans school districts from requiring teachers to notify parents if their children change their gender identification.

“This is the final straw,” Mr. Musk posted on X. It is “attacking both families and companies.” He added that he had previously warned the California governor of such consequences.

SpaceX will move its headquarters from Hawthorne, Calif., to its Starbase facility in Boca Chica, Texas. X, which is based in San Francisco, will move to Austin, Mr. Musk said.

SpaceX, X and Mr. Musk did not immediately respond to requests for comment.

Mr. Musk previously staged a political protest against California, moving Tesla’s headquarters from Palo Alto, Calif., to Austin, Texas, in the wake of the Bay Area’s tough coronavirus lockdowns. Mr. Musk, who is the chief executive of the auto manufacturer, called restrictions that made its Fremont, Calif., factory shut down “fascist.”

This is a developing story. Check back for updates.

The New York Times wants to hear from employees of SpaceX and X who may be affected by this move.