They work just like normal sails. A sail is just a wing sideways. It moves the ship by generating lift.
The ship moves forward when the angle of attack is adjusted correctly. See the picture: https://en.wikipedia.org/wiki/Point_of_sail#/media/File:Poin... The ship can't move directly against the wind, but it can close-haul 45 degrees against the wind assuming it has enough keel.