The US-based firms have agreed to speed up their reactions when illegal material is flagged up, with the aim of looking at all suspicious material within 24 hours.
"The recent terror attacks have reminded us of the urgent need to address illegal online hate speech," EU Justice Commissioner Vera Jourova said in a statement, referring to attacks in Paris and Brussels claimed by the Islamic State jihadist group.
"I welcome the commitment of worldwide IT companies to review the majority of valid notifications for removal of illegal hate speech in less than 24 hours and remove or disable access to such content, if necessary."
The code of conduct also involves the Internet companies building stronger relations with civil society groups that flag up content that incites hate or violence.
The US firms insisted that following the EU rules would not compromise freedom of speech.
"We remain committed to letting the Tweets flow. However, there is a clear distinction between freedom of expression and conduct that incites violence and hate," said Twitter's Head of Public Policy for Europe, Karen White.
Monika Bickert, Head of Global Policy Management at Facebook, said they "welcome today's announcement and the chance to continue our work with the Commission and wider tech industry to fight hate speech."
"We urge people to use our reporting tools if they find content that they believe violates our standards so we can investigate. Our teams around the world review these reports around the clock and take swift action," she added.