When wind passes an object it creates forces on it. By convention, a force arising at right angles to the wind direction (not right angles to the sail) is called lift. A force acting in the direction of the wind is called drag. In addition to this one can say that a torque is created by the wind (as you mention). If the boat is sailing to windward, the lift can be resolved into two components: one acting in the desired direction and another acting sideways on the boat. This is resisted by the under water foils/hull shape providing underwater lift. In addition to the torque arising from the sail itself, torque arises from the relative positions of the "air" and "water" centres of pressure. This is opposed by torque created by the lift of the rudder. The underwater foils work the same as the wings and tail plane of an aircraft. When a glider is flying at an angle of sink, that is creating an angle of attack for its wings. And the glide slope is analogous to the leeway of a sailing boat, which in the same way creates an angle of attack for the centre board/keel and provides water lift to oppose the sideways wind forces.