In the yearslong technology fight between the U.S. and China, the Americans are poised to land a major punch.

The House on Saturday easily passed a bill that would force a sale or ban of TikTok, which is owned by China  based ByteDance, bringing closer to reality a law that could remove the popular app and deepen the internet divide between the two countries.

The measure, which passed 360-58 and was tied to a sweeping aid package for Israel and Ukraine , would give ByteDance up to a year to sell the app—compared with the six-month period proposed in a prior bill.

If ByteDance can’t find a buyer within that time, TikTok—which has 170 million users in the U.S.—would be banned.

The Senate could vote on the bill in coming days. President Biden has previously said that he would sign such a bill into law.

TikTok on Saturday reiterated a statement it gave when the package was introduced that called it “unfortunate that the House of Representatives is using the cover of an important foreign and humanitarian assistance to once again jam through a ban bill.” The company has said the legislation is effectively a ban, since completing a deal would be difficult.

Amid the drama in Washington, Erich Andersen , general counsel for TikTok and ByteDance, told staff Sunday that he’s planning to leave the company, according to an internal note reviewed by The Wall Street Journal. The timeline is uncertain, according to people familiar with the matter. Andersen will help find his successor.

“As I started to reflect some months ago on the stresses of the last few years and the new generation of challenges that lie ahead, I decided that the time was right to pass the baton to a new leader,” he said in the note. Andersen described his impending exit as amicable. Bloomberg and The Information earlier reported on Andersen’s upcoming departure from TikTok.

The Chinese government has signaled it wouldn’t allow a forced sale of the company. TikTok says it has never been asked to provide U.S. user data to the Chinese government and wouldn’t do so if asked to.

Passage of the legislation, which targets China’s most internationally successful app, comes as China steps up its longstanding campaign against U.S. and other foreign messaging and social-media services.

Earlier this week, Beijing forced Apple to help close a loophole that some Chinese users had been exploiting to access already-banned services, including two of Meta ’s apps, WhatsApp and Threads.

To some experts, it was seen as a small move—given that the country has already banned many outside social-media services and messaging apps—but indicative of China’s intentions to further push foreign companies out.

“The direction is clear,” said Dan Wang , a visiting scholar at Yale Law School’s Tsai China Center. “The walls are going up.”

Social media and messaging apps are in the crosshairs in particular because they have such a powerful ability to transmit information broadly and influence public opinion, as well as potentially to collect data about their users.

Some lawmakers who supported the TikTok bill argued that it’s fair game to ban the app since U.S. social-media apps are banned in China.

China more than a decade ago banned Facebook, Google, Twitter, YouTube and most other sites on the mainstream Western internet. People in China got around the bans by using a virtual private network to make their phones think they were accessing the internet from a country where the sites and apps weren’t blocked.

Given TikTok’s popularity with teens and young adults, many lawmakers worry Beijing could use the app to gather data on users or promote China’s preferred messaging on topics such as the Israel-Hamas war. PHOTO: RACHEL MUMMEY FOR THE WALL STREET JOURNAL

On Friday, China took action to stop that from happening, ordering Apple to take certain apps off the app store entirely to prevent them from being downloaded via VPN.

Over the past decade, Instagram, X, Facebook, YouTube and WhatsApp were collectively downloaded from Apple’s app store in China more than 170 million times, according to estimates from market intelligence firm Sensor Tower.

China cited national-security concerns—the same reason U.S. lawmakers have given for trying to separate TikTok from ByteDance. They say they’re worried that Beijing could use the app to gather intelligence on U.S. users or promote China’s preferred messages to users on a range of sensitive issues, including the Israel-Hamas war.

U.S. social-media apps like Instagram and YouTube would likely be the biggest beneficiaries of a TikTok ban. The same proved true in China: WeChat , a Chinese-owned app, has become the most popular social-media platform there in the absence of Western ones.

Still, U.S. tech executives have had differing views on a potential TikTok ban. In 2020, Meta Platforms Chief Executive Mark Zuckerberg   stoked fears in Washington about TikTok’s foreign ownership. He has since taken a more nuanced stance, saying in 2022 that it’s a complicated matter. Elon Musk , owner of the social-media platform X, tweeted Friday in support of the TikTok app.

“TikTok should not be banned in the USA, even though such a ban may benefit the X platform,” he wrote. “Doing so would be contrary to freedom of speech and expression.”

There are political risks for both parties in pushing the TikTok legislation, given how popular the app has become, especially among young people who have been a reliable voting bloc for Democrats. President Biden’s campaign recently joined TikTok. Former President Donald Trump , who previously tried to ban TikTok via executive order, says he is now less sure of how the app should be handled.

A TikTok ban could face legal challenges from the company or from video creators who depend on the platform for their livelihoods. China could take retaliatory action.

A TikTok ban could face challenges not only from ByteDance, but also from among the content creators whose earn a living on the platform. PHOTO: ALYSSA SCHUKAR FOR THE WALL STREET JOURNAL

Wang, the Yale visiting scholar who previously lived in China, described the action this week by the Chinese government as “a signal that China might do more if the U.S. does move ahead with a TikTok ban,” though the country’s escalation path is fairly limited.

“They’ve already done everything they can to squeeze out information platforms,” he said.

Beyond the TikTok ban, tensions over technological reliance and influence have been brewing between the U.S. and China for some time, with both sides periodically making moves to distance themselves from each other.

Huawei, which for a time was the No. 1 smartphone maker in the world by volume, was devastated by U.S. sanctions in 2019 that prevented U.S. companies from selling directly to the Chinese-owned telecommunications company. The move effectively meant Huawei could no longer buy wireless-communications chips from U.S.-based Qualcomm and had to find a new source.

On the flip side, China earlier this year told the nation’s largest telecom carriers to phase American chip makers out of their devices by 2027—a move that would affect U.S. chip giants Intel and Advanced Micro Devices .

Eventually, there could be little overlap between the technology allowed and used in each of the two countries, industry experts say.

“The divide is coming,” said Andrew King, a venture capital partner at Bastille Ventures who works with the House Select Committee on the Chinese Communist Party.

Write to Meghan Bobrowsky at meghan.bobrowsky@wsj.com