A smart contract is a self-executing contract with the terms of the agreement directly written into code. It automatically enforces and executes actions when predefined conditions are met, often on a blockchain.