Countries such as the US, Canada and Singapore are expected to follow with similar rules in the coming months.
The time of big online platforms behaving like they are 'too big to care' is coming to an end
It comes after years of frustration over antitrust enforcement being too slow or inefficient. Senior EU officials hailed it as a turning point in regulating Big Tech.
Thierry Breton, commissioner for the internal market, said: "The time of big online platforms behaving like they are 'too big to care' is coming to an end."
The DSA aims to make the internet safer for consumers. Internet companies will have to offer terms and conditions that are understandable even to children. Targeting users online based on their religion, gender or sexual preferences are among the practices to be banned.
Internet platforms such as Twitter will have to be transparent in the way they recommend content to their users. They will also have to be properly staffed to deal with content moderation because users will have the right to complain in their own language.
Those who breach the rules face heavy fines and bans from operating within the EU.
The new legislation sets clear obligations for platforms that are designed to be proportionate to size, impact and risk, Breton said.
The commission will be able to "impose effective and dissuasive sanctions of up to 6 per cent of global turnover or even a ban on operating in the EU single market in case of repeated serious breaches", he added.
Margrethe Vestager, the EU's executive vice-president in charge of digital policy, said the new rule book would "help create a safe and accountable online environment".
She said: "Platforms should be transparent about their content moderation decisions, prevent dangerous disinformation from going viral and avoid unsafe products being offered on market places. With today's agreement we ensure that platforms are held accountable for the risks their services can pose to society and citizens."
MEPs hailed the legislation, while tech companies said they would have to look at the fine print.
Dita Charanzova, vice-president of the European Parliament, said it had been a long and hard negotiation. "Google, Facebook and other large online platforms will have to act to better protect their users. Europe has made clear that they cannot act as independent digital islands."
Christel Schaldemose, the MEP leading the discussions on behalf of the parliament, told the Financial Times: "With the DSA we will make the platforms responsible for their algorithms, they have to do risk assessment and risk mitigation to protect us."
Google, whose search engine is likely to fall within the scope of the regulation, said: "As the law is finalised and implemented, the details will matter."
Victoria de Posson of the Computer and Communications Industry Association said: "A number of important details still remain to be clarified. We hope that the final legislation will allow all companies, both large and small, to comply with the rules in practice, enabling Europeans to continue to enjoy the many benefits of digital services."