You will hear all sorts of explanations about how a sail works. Of course, we can all agree on how a sail works when you're sailing "downwind". Basically the sail acts like a big board that the wind pushes against, and that makes the boat move with the wind. Easy-peesey. But how does a sail manage to pull the boat into the wind?
Essentially, the sail is shaped in such a manner as to act like an airplane wing that's stood on its end. Rather than lifting upwards like a plane wing, it lifts kind of "sideways".
Some people hold that the cause is due to something called Bernoulli's Principle. Bernoulli principle does exist and is a real thing. It basically states that the faster a fluid is moving in one direction, the less it will exert pressure in another direction. Basically, it gets so busy concentrating on what's in front of it that it doesn't have any attention to push sideways. Let's use a solid airplane wing as an example. Here is a picture of their explanation:
Why is this an incorrect theory? Let's follow along it for a moment. At the left side are a blue and red dot. Let's pretend those are two air molecules. They are hanging about in the air minding their own business when along comes this rude object that separates them (the airplane wing). The theory is that the one moving over the top of the wing has further to go, which is correct. However, it then makes the assumption that it wants to travel that distance in the same amount of time and rejoin the red dot at the back of the wing. It has no actual reason to do that. It would be just as happy meeting up with a different air molecule at the far end. And, in wind tunnel tests, that's exactly what happens. There's no reason for it to "speed up". Since it doesn't move faster than the one on the bottom, there's no difference in pressure and so the wing has no "lift".
So if that reason is incorrect, what IS the reason?
For this we need to revisit one of "Newton's Laws of Motion", more specifically, his first law. This is an easy one, fortunately. "An object will remain at rest or in uniform motion in a straight line unless acted upon by an external force." Basically, a thrown baseball isn't going to suddenly change direction unless something pushes it.
Instead of trying to line up the dots and make them come together at the end, let's look at the shape of the path that each molecule has to take. At the front of the wing, both molecules abruptly move in nearly opposite directions. There's no real difference between them there. However, the top molecule has to change direction quite a bit more to flow over and stay next to the wing than the bottom molecule does. That means more "force" applied to it somewhere. That same force, by another of Newton's laws, is also, eventually, applied to the plane wing in the opposite direction. Since the air is accelerated “down” around the curve, the wing (due to the “equal and opposite reaction” rule) is accelerated upwards.
Ok, but that's an airplane. What does this have to do with sailing?
If you could fly, or perhaps put a camera on a drone, and look down at the sail from above, you'd see that there are striking similarities between the shape of the sail and the shape of an airplane wing standing on end. Whenever you're sailing on anything except downwind, the sail is a soft wing and is generating lift which pulls the boat forward.