A foreign key is a database constraint that creates a relationship between two tables by linking a column or a set of columns in one table to the primary key of another table. This ensures referential integrity, meaning that the foreign key column must contain values that exist in the referenced primary key column or be null.