Belgium’s privacy watchdog said the website had broken privacy laws by placing tracking code – known as cookies – on third-party websites.
Facebook said it would appeal against the ruling.
The social network faces fines of 250,000 euros (£221,000, $311,000) a day if it does not comply.
The court said Facebook must “stop following and recording internet use by people surfing in Belgium, until it complies with Belgian privacy laws”.
“Facebook must also destroy all personal data obtained illegally.”
The ruling is the latest in a long-running dispute between the social network and the Belgian commission for the protection of privacy (CPP).
In 2015, the CPP complained that Facebook tracked people when they visited pages on the site or clicked “like” or “share”, even if they were not members.
It won its case, but Facebook had the verdict overturned in 2016.
Now the court has again agreed with the findings of the CPP.
Facebook said it was “disappointed” by the verdict.
Richard Allan, the company’s vice-president of public policy in Europe, said: “The cookies and pixels we use are industry standard technologies, and enable hundreds of thousands of businesses to grow their businesses and reach customers across the EU.”
The company has been told to delete all the data it had gathered on people who did not use Facebook. The court ruled the data was gathered illegally.