Surfactant molecules collect at the boundary between water and grease. Their water-avoiding tails can associate with oily material while their water-friendly heads remain in contact with the water.
With agitation, grease can break into tiny droplets surrounded by surfactant molecules. These structures help keep oily material dispersed in the wash water instead of immediately sticking back to the surface.
Soap also lowers surface tension, allowing water to wet a surface more effectively. Real detergents often combine several surfactants with builders, enzymes or other ingredients for specific kinds of dirt.