Twitter Inc. said it would appoint Tesla Inc. Chief Executive Elon Musk to its board, essentially bringing the billionaire social-media agitator inside the fold.

Mr. Musk on Monday disclosed a 9.2% stake in the company, making him its largest shareholder. He has been one of its louder critics, assailing the platform on free-speech grounds. His frequent, colorful use of Twitter has also landed him in occasional legal trouble.

Twitter shares soared over 27% on Monday, after Mr. Musk’s position in the company was first disclosed and advanced roughly 4% on Tuesday.

Twitter Chief Executive Parag Agrawal said the company had been in conversations with Mr. Musk for several weeks.

“He’s both a passionate believer and intense critic of the service which is exactly what we need on @Twitter, and in the boardroom, to make us stronger in the long-term. Welcome Elon!” Mr. Agrawal tweeted.

Mr. Musk tweeted: “Looking forward to working with Parag & Twitter board to make significant improvements to Twitter in coming months!”

Mr. Musk’s board term is set for two years. So long as he remains a director, he can’t own more than 14.9% of the company’s stock, according to a securities filing. While neither Twitter nor Mr. Musk would comment on that cap, the law in Delaware—Twitter’s legal home—makes it difficult for an investor who owns more than 15% to launch a hostile bid for a company, providing management a modest measure of protection.

The Tesla and SpaceX CEO has used the service for years to opine on everything from cryptocurrencies to free expression. That opens up a potential area of tension between the company and Mr. Musk over content moderation, analysts said.

The social-media platform has suspended some users, including then-President Donald Trump

in 2021, for comments made on the platform, and placed labels on posts to stop what it says is the spread of false information. Mr. Musk has described himself as “a free speech absolutist.”

Last month, Mr. Musk said he would only block Russian news sources from the satellite-based internet service provided by his space company “at gunpoint.” The comment came at a time many Western companies put limits on Russian media over Moscow’s invasion of Ukraine.

Later, Mr. Musk tweeted a poll, saying, “Free speech is essential to a functioning democracy. Do you believe Twitter rigorously adheres to this principle?” More than 70% of the roughly two million accounts that voted said no.

In landing a board seat, Mr. Musk will be in a position “to really kick up dirt,” said AB Bernstein analyst Mark Shmulik.

“He moved from the back seat of the car to the front seat of the car. In fact, he’s probably the driver.”

Boasting more than 80 million followers, Mr. Musk is a master operator on Twitter. While rivals to Tesla spend heavily on brand or product advertisement, Mr. Musk effectively acts as his company’s chief marketing officer with tweets that reach audiences far beyond his immediate followers.

Mr. Musk, whose regulatory filing identifies him as a passive investor, hasn’t specified what, if any, formal plans he has to change Twitter. On Monday, he asked his Twitter followers to vote on whether the company should add the ability to edit existing tweets.

“We believe one of Musk’s main motives could be to influence TWTR’s moderation policies, which he has often criticized as being too restrictive,” Brent Hill, an analyst at Jefferies wrote in an investor note, using Twitter’s stock symbol.

Any loosening of content restrictions could also backfire with advertising customers, said Brian Wieser, global president of business intelligence at GroupM, a part of ad giant

WPP PLC. “Advertisers don’t want their brands associated with advocations for insurrection or advocations for hate and harm,” Mr. Wieser said. “They don’t want to associate with environments which create a toxicity for people who might be using the platform.”

Mr. Musk hasn’t been shy about questioning Twitter’s values. After building his stake in the company, he mused publicly in recent weeks about Twitter’s commitment to free speech and even said he was considering starting a rival social-media platform of his own.

Twitter will have 12 board members, including Mr. Agrawal and co-founder Jack Dorsey. In a tweet, Mr. Dorsey said that he welcomed Mr. Musk onto the board. “He cares deeply about our world and Twitter’s role in it,” Mr. Dorsey wrote.

Mr. Musk remains on the board of at least two other companies: Tesla and rocket company Space Exploration Technologies Corp., as SpaceX is formally known.

The manner in which Mr. Musk disclosed his investment in Twitter could flare tensions between him and the U.S. Securities and Exchange Commission, securities lawyers say. He was late in disclosing his 9.2% holding on a form that investors are required to file when they buy more than 5% of a company’s stock, without planning to seek control. The filing also didn’t include a standard certification that underscores an investor’s passive status.

Write to Sarah E. Needleman at sarah.needleman@wsj.com and Meghan Bobrowsky at Meghan.Bobrowsky@wsj.com