TikTok could be banned in the US unless it is sold by its Chinese parent company ByteDance.
The video sharing app has millions of users worldwide, but has faced questions over the security of users' data and its links to the government in Beijing.
Lawmakers from both major US political parties have called for a law that bans TikTok unless ByteDance agrees to sell the app to a non-Chinese company.
They fear the Chinese government could force ByteDance to hand over data about TikTok's 170 million US users. TikTok insists it would not provide foreign user data to the Chinese government.
The House of Representatives and Senate have now both approved a $95bn (£76bn) foreign aid package with funds for Ukraine, Israel and Taiwan which also contained a bill paving the way for the forced sale of TikTok.
The legislation has been signed into law by President Joe Biden.
Previous attempts to block the app in the US on national security grounds have failed.
Former US President Donald Trump tried to ban the app when he was in the White House in 2020.
But Mr Trump – the Republican 2024 presidential candidate – has criticised the new legislation, arguing that limiting TikTok would unfairly benefit Facebook.
Although Mr Biden has signed the bill into law, it does not mean an immediate US ban for TikTok.
The legislation gives ByteDance nine months to sell TikTok to a new buyer, with an additional three-month grace period, before any ban would take effect.
That means that the sale deadline would most likely come some time in 2025, after the winner of the 2024 presidential election takes office. If Mr Trump wins, he may seek to block the ban from being implemented.
TikTok has vowed to fight the forced sale in the courts, which could take years.
The most straightforward way for the US to ban TikTok would be to remove it from app stores, such as those operated by Apple and Google for iOS and Android devices.
App stores are how most people download apps on to their smartphones and tablets, so the ban would stop new users from getting TikTok.
It would also mean that people who already had the app would no longer be able to get future updates designed to improve security or fix bugs.
The bill forbids applications controlled by US adversary countries from being updated and maintained in the US.
It gives broad powers to the president to limit apps with ties to Russia, China, Iran and North Korea.
TikTok has called the legislation an "unconstitutional ban" and affront to the US right to free speech.
"We are confident and we will keep fighting for your rights in the courts," said TikTok boss Shou Zi Chew. "Rest assured," he told users in a video, "we aren't going anywhere".
He previously said the bill would give its social media rivals more power and put thousands of American jobs at risk.
ByteDance would also have to seek approval from Chinese officials to sell TikTok, but Beijing has vowed to oppose such a move.
Many US creators and users have criticised the potential ban.
Tiffany Yu, a young disability advocate from Los Angeles, told the BBC at a protest outside the White House the platform was vital to her work.
This video can not be played
Watch: How do young Americans feel about a ban on TikTok?
In March 2024, TikTok asked its 170 million US users to contact their political representatives and ask them not to support the bill.
But the deluge of "confused" calls from TikTok users to congressmen and senators seemingly backfired.
Several politicians said the campaign worsened the concerns they had about the app, and strengthened their resolve to pass the legislation.
It is thought the US TikTok bill could inspire similar moves elsewhere.
TikTok is already banned in India, which was one of the app's largest markets before it was outlawed in June 2020.
It is also blocked in Iran, Nepal, Afghanistan and Somalia.
The UK government and Parliament banned TikTok from staff work devices in 2023, as has the European Commission.
The BBC also advised staff to delete TikTok from corporate phones because of security fears.
At the heart of TikTok is its algorithm, a set of instructions which determines which content is presented to users, based on data about how they engaged with previous material.
Users are offered three main feeds on their app – Following, Friends and For You.
The Following and Friends feeds present users with content from people they have chosen to follow and who follow them back, but the For You feed is automatically generated by the app.
This curated feed has become the main destination for users looking for new content, and creators hungry for the millions of views TikTok videos can clock up if they go viral.
Critics say the app collects more data than other social media platforms in order to power its highly personalised system.
This can include information about users' location, device, the content they engage with and keystroke rhythms they exhibit while typing.
But popular social media apps such as Facebook and Instagram collect similar data from users.
Key mayor results due after Labour notches up local election wins
Chris Mason analysis: Bleak picture for Sunak as Tories take election hit
Why North Korea's latest propaganda bop is a huge TikTok hit
'Tories crushed' as rebels 'end plot to oust Sunak'
Find the local election results in your area
When is the next general election?
What can fans expect from final Gavin and Stacey episode?
Sweden prepares for Eurovision with heightened security
Ryan Gosling plays one, but what makes a real stunt actor?
Call for gardeners to help with flood defence
How my idea became Minecraft's biggest tournament
Voting, Volcanoes and Vatican Guards: Photos of the week
Detective Davis Lindo is thrown in at the deep end
With partner DCI Bartlett, can he impress, or will his approach leave him out in the cold?
Charlotte Church explores her working class childhood
Join the Welsh singing legend for honest, hilarious conversations with her Cardiffian family
Fancy a film night tonight?
From comedy to thrillers, there's something for everyone on BBC iPlayer
The man who continued fighting WW2 until 1974
Hiroo Onoda spent 30 years fighting in the jungle, believing the war was still going on
Revisit this classic British sitcom
The chaos caused by WhatsApp mishaps
Is the party in Ibiza nearly over?
Unveiling the future of ABBA
© 2024 BBC. The BBC is not responsible for the content of external sites. Read about our approach to external linking.

More Stories
Community Snapshot—June
New ITU Report Finds Community Networks Are Key to Reaching the Unconnected
Digital Coercion: How Inaccessible Design Strips Financial Privacy