The US Senate on Tuesday approved legislation requiring the wildly popular social media app TikTok to be divested from its Chinese parent company ByteDance or be shut out of the American market.

The measure was part of a $95 billion foreign aid package, including military assistance to Ukraine, Israel and Taiwan, which has now cleared Congress and heads to President Joe Biden's desk.

US and other Western officials have voiced alarm over the popularity of TikTok with young people, alleging it allows Beijing to collect data and spy on users. It has 170 million users in the United States alone.

These critics also say TikTok is subservient to Beijing and a conduit to spread propaganda. China and the company strongly deny these claims.

The bill, which could trigger the rare step of barring a company from operating in the US market, passed the Senate by a 79-18 vote three days after it cleared the House of Representatives with strong bipartisan support.

Biden has stated he will sign the legislation.

He reiterated his concerns about TikTok in a rare telephone conversation with Chinese President Xi Jinping early this month.

TikTok complained after Saturday's House vote, saying it was "unfortunate" that lawmakers sought to "jam through a ban bill that would trample the free speech rights of 170 million Americans, devastate seven million businesses, and shutter a platform that contributes $24 billion to the US economy, annually."

Under the bill, ByteDance would have to sell the app within a year or be excluded from Apple and Google's app stores in the United States.

Steven Mnuchin, who served as US treasury secretary under Biden's predecessor Donald Trump, has said he is interested in acquiring TikTok and has assembled a group of investors.

TikTok for years has been in the crosshairs of American authorities, who say the platform allows Beijing to snoop on users in the United States. But a ban could trigger lawsuits.

The bill passed by Congress gives the US president the authority to designate other applications as a threat to national security if they are controlled by a country deemed hostile.

Elon Musk, the billionaire owner of X, formerly Twitter, came out Friday against banning TikTok, saying "doing so would be contrary to freedom of speech and expression."