A syntax error is an error in the syntax or structure of a program that prevents it from being executed. It occurs when the interpreter or compiler encounters a line of code that does not follow the rules of the programming language.