There are two kinds of sailboats. There's the big square sailed ones which always have to move downwind. Then there are the triangular sailed ones, which can move in any direction except for right into the wind. (Maybe a 30 degree on each side dead zone).
The square sailed boats can't move faster than the wind, as they just rely on the air pushing on the sail to move with the wind.
That's also how the triangular sailed boats move when moving directly downwind. They too can't outrun the wind.
However, when moving sideways to the wind, the wind passes over the sail, which looks like a wing sticking out of the water. Like a wing, there's a "lift" force generated, although it's not up but sideways. The boats also have a fin sticking into the water, which prevents the boat from slipping directly along with that "lift" force, and instead move forward.