diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h
index 608d53151c..8f2ef296c3 100644
--- a/include/libcamera/internal/egl.h
+++ b/include/libcamera/internal/egl.h
@@ -104,6 +104,7 @@ public:
 	~eGL();
 
 	int initEGLContext();
+	void resetEGLContext();
 	static EGLDisplay probeDisplay();
 
 	int createInputDMABufTexture2D(eGLImage &eglImage, int fd);
diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp
index 2a1f577845..1f9e743c2f 100644
--- a/src/libcamera/egl.cpp
+++ b/src/libcamera/egl.cpp
@@ -73,12 +73,13 @@ eGL::eGL(EGLDisplay display)
 /**
  * \brief Destroy the EGL helper
  *
- * Destroys the EGL context and surface if they were successfully created.
+ * An instance must only be destroyed if there is no active EGL context.
+ *
+ * \sa resetEGLContext()
  */
 eGL::~eGL()
 {
-	if (context_ != EGL_NO_CONTEXT)
-		eglDestroyContext(display_, context_);
+	ASSERT(context_ == EGL_NO_CONTEXT);
 }
 
 /**
@@ -368,6 +369,8 @@ void eGL::createOutputTexture2D(eGLImage &eglImage)
  * - eglCreateImageKHR / eglDestroyImageKHR
  * - glEGLImageTargetTexture2DOES
  *
+ * Each successful invocation must be followed by a call to resetEGLContext().
+ *
  * \return 0 on success, or -ENODEV on failure
  */
 int eGL::initEGLContext()
@@ -444,6 +447,24 @@ fail:
 	return -ENODEV;
 }
 
+/**
+ * \brief Destroy the EGL context
+ *
+ * This function destroys the EGL context created by initEGLContext().
+ * If there is no valid EGL context, this function has no effect.
+ */
+void eGL::resetEGLContext()
+{
+	if (context_ != EGL_NO_CONTEXT) {
+		assertThread(),
+		eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+		eglDestroyContext(display_, std::exchange(context_, EGL_NO_CONTEXT));
+	}
+
+	tid_ = -1;
+	vtable_ = {};
+}
+
 /**
  * \brief Make the EGL context current for the calling thread
  *
diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp
index 7b2b367305..97aa037935 100644
--- a/src/libcamera/software_isp/debayer_egl.cpp
+++ b/src/libcamera/software_isp/debayer_egl.cpp
@@ -680,6 +680,8 @@ void DebayerEGL::stop()
 
 	if (programId_)
 		glDeleteProgram(programId_);
+
+	egl_.resetEGLContext();
 }
 
 SizeRange DebayerEGL::sizes(PixelFormat inputFormat, const Size &inputSize)
