Facebook Inc. said Monday that it would work with the German Justice Ministry to fight xenophobic and racist messages on the social network’s platform, bending to government pressure to clamp down on hate messages against migrants online.

German Justice Minister Heiko Maas said after a meeting with Facebook executives in Berlin that the ministry would coordinate the creation of a task force with Facebook and other Internet competitors to evaluate whether inappropriate content flagged by users falls under freedom of speech...