I need 'em both to explain this.
Nobody has any difficulty understanding how a sailboat can sail directly downwind. All you need is lots of square feet of sail up there. The wind pushes on the sail, the sail pulls the boat. Piece of cake.
And it is not a very big leap to sailing at 45 degrees from downwind. The boat has a keel, which serves to make it difficult to push it sideways in the water. So, you put the sail up angled to catch the most wind, except that now it will be pulling the boat partly sideways. You pretty much still go where you want. But the keel is not on rails, so there is some, small sideways slippage, towards the downwind, or leeward direction. (This slippage is known as leeway - the origin of the common usage of the word.)
But upwind?? How does that work?
Well, first a sailboat cannot go directly upwind, into the eye of the wind. The best it can do is about 45 degrees either side of the eye of the wind. But how?
Those sails are not just big bedsheets up there. They are carefully constructed to have a particular shape when they are full of wind. If you looked at a horizontal cross section of a loaded sail, you might recognize the shape - it is the same general shape that an airplane wing has. And we know what air flowing over an airplane wing does: It provides lift. It is the air flowing over the carefully shaped wings of a 747 that keeps that million pounds up there.
Now imagine an airplane wing turned up on end: starting to look like a sail, isn't it (in fact, some high-speed racing boats have been built with solid "sails" that bear a whole lot more resemblance to airplane wings than cloth sails). Which way does the lift on the airplane wing pull? Well, up, of course. But when that wing is tipped up on end, the lift is sideways, pulling on the curved side (wings are flat on the bottom, aren't they).
Now come back to the sails. When sailing upwind, the sails are not oriented to catch the most wind. Instead, now is when all that carefully engineered shape comes into play. They are oriented so that the wind flows over them, like that airplane wing. And like the airplane wing, they generate lift. So, sailing upwind, the wind is pulling on the sails.
Still, how does that move the boat? I am not going to draw vector diagrams here. Instead, here's an analogy: the pumpkin seed. Huh? I know it is early for Hallowe'en, but imagine that you have pulled a fresh, slimy pumpkin seed out of a pumpkin. Now, put that seed between your thumb and forefinger, and squeeze it. If your finger tips are the slightest bit out of parallel, that seed is going to squirt out. Now come back to the boat... one "finger" is the wind, pulling the boat, and the other is the keel, preventing it from going (very much) sideways. The result of being pinched between the wind and the keel? It squirts forward. That's the best I can do without vectors.
There is also art and careful engineering in the arrangement of the sails on the boat, beyond the effort to get the most square feet in the wind within the physical constraints of the boat. Again, the airplane. Next time you are on final approach, look at what the pilot has done to the wings. In flight they are streamlined. But on final approach, when airspeed is much lower, the same lift is still needed, or the plane will fall out of the sky. To generate this extra lift at low speed, the pilot changes portions of the wing to create slots at the front of the wing. The air moving thru the slots is greatly accelerated, thereby providing the missing but needed lift.
Now look at the slots created by this boat's sails:
There are three of them, and because the sails are arranged one ahead of the next, they each accelerate the flow for the next one. The effect is very real, and amazing. On a light wind day, if you go forward and stand in the slot between the main and jib, the wind will be very significantly stronger than if you stand in the more or less free air at the stern. And it works, very, very well.
After all, that 747 stays up there...