A foreign key is a specific kind of constraint.
A constraint is a rule that restricts the values in a database.
Please follow this link to find detailed answer (It's for Oracle, not MySql, but the foreign key works in the same way in all databases):
http://docs.oracle.com/cd/B19306_01/server.102/b14200/clauses002.htm
Use a constraint to define an integrity constraint--a rule that
restricts the values in a database. Oracle Database lets you create
six types of constraints and lets you declare them in two ways.
The six types of integrity constraint are described briefly here and
more fully in "Semantics":
A NOT NULL constraint prohibits a database value from being null.
A unique constraint prohibits multiple rows from having the same value
in the same column or combination of columns but allows some values to
be null.
A primary key constraint combines a NOT NULL constraint and a unique
constraint in a single declaration. That is, it prohibits multiple
rows from having the same value in the same column or combination of
columns and prohibits values from being null.
A foreign key constraint requires values in one table to match values
in another table.
A check constraint requires a value in the database to comply with a
specified condition.
A REF column by definition references an object in another object type
or in a relational table. A REF constraint lets you further describe
the relationship between the REF column and the object it references.
As you see from the definition - the foreign key is a constraint, that works in such a way, that it simply checks if a given value in a column of one table exists in a given column of another table.