This is obviously possible, since sailing boats have been doing it since time immemorial. But how is it possible?
The kind of boat shown can’t sail directly upwind, but it can sail somewhat upwind at an angle to the wind.
In the diagram,
W is the wind;
S is the force on the sail (caused by the wind)
K is the force on the keel (caused by sideways movement of the boat as it’s pushed by the wind)
P is the pressure of the wind on the sail, or the water on the keel – this is not quite the same as the forces on the sail or the keel, because of drag. The pressure acts at right-angles (perpendicular) to the sail or keel, but the drag, the force of friction of the air sliding past the sail or water sliding past the keel, acts parallel to them.
R is the resultant force on the boat, the sum of the forces on the sail and on the keel. Most of the forces actually balance out, being almost in opposite directions, but the forwards component of the force on the sail is greater than the backwards component of the force on the keel. The boat actually moves in the direction of this resultant force.
(One interesting point is that the performance of a sailing boat depends on the ratio of the pressures to the drags – this is the same ratio as the lift:drag ratio of a aircraft’s wing – or indeed of the whole aircraft. The exact shape of the boat’s hull, keel and sail affect the lift:drag ratio, and hence the performance of the boat, in the same sort of way that the shape of an aircraft’s wings and fuselage affect the performance of the aircraft.)
By sailing across the wind alternately one way and then the other, you can make your way upwind. For more about this, see Beating Upwind.