Between physics and hydrodynamics
A structural beam that runs from the bow to the stern of a ship and sits lower than the rest of the hull, the keel was invented by the Vikings. Because their sailboats were square-rigged, they were prone to a lot of leeway when tacking close to the wind.
Without the keel as we know it now, the sailing we know under sail would undoubtedly be dangerous.
The keel has two main functions: to prevent the boat from being dragged sideways by the wind (lateral resistance) and to maintain ballast. Ballast is a weight traditionally at the bottom of the keel that keeps the boat upside down.
When the sails interact with the wind, there is also a lot going on underwater to help create lift and allow the boat to recover from the tack. When a ship heels, or leans to one side in one direction when tacking, ballast prevents it from capsizing completely. Placed under the sailboat towards the center of the bottom of the hull, the wide, flat surface of the keel creates a lateral force by displacing the water in the opposite direction to that in which the boat is leaning.
Hydrodynamics in action
Although the keel has a much smaller surface area than the sails, the density of the water allows it to initiate a force strong enough to cancel the heeling motion. The resulting equilibrium is called the righting moment.