A semantic error occurs when a program compiles and runs, but the output is not what the programmer intended due to incorrect logic or meaning in the code. These errors are often more challenging to detect and fix than syntax errors because they require an understanding of the program's intended behavior.