diff --git a/gcc/testsuite/c-c++-common/cpp/pragma-message-trad.c b/gcc/testsuite/c-c++-common/cpp/pragma-message-trad.c
new file mode 100644
index 00000000000..0478e6fc7c7
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/pragma-message-trad.c
@@ -0,0 +1,9 @@
+/* { dg-do preprocess } */
+/* { dg-options "-traditional-cpp" } */
+/* PR preprocessor/79516 */
+
+#pragma message "OK"
+
+#if 0
+#pragma message ("Not printed")
+#endif
diff --git a/libcpp/directives.cc b/libcpp/directives.cc
index 6b0d691f491..9c0f77ab017 100644
--- a/libcpp/directives.cc
+++ b/libcpp/directives.cc
@@ -323,6 +323,8 @@ end_directive (cpp_reader *pfile, int skip_line)
       /* Revert change of prepare_directive_trad.  */
       if (!pfile->state.in_deferred_pragma)
 	pfile->state.prevent_expansion--;
+      /* No longer inside a deferred pragma. */
+      pfile->state.in_deferred_pragma = false;
 
       if (pfile->directive != &dtable[T_DEFINE])
 	_cpp_remove_overlay (pfile);
