diff --git a/src/wp-includes/class-wp.php b/src/wp-includes/class-wp.php
index b3bc907..1e274f5 100644
--- a/src/wp-includes/class-wp.php
+++ b/src/wp-includes/class-wp.php
@@ -257,13 +257,13 @@ class WP {
 
 				// If we're processing a 404 request, clear the error var since we found something.
 				if ( '404' == $error ) {
-					unset( $error, $_GET['error'] );
+					unset( $error );
 				}
 			}
 
 			// If req_uri is empty or if it is a request for ourself, unset error.
 			if ( empty( $requested_path ) || $requested_file == $self || strpos( $_SERVER['PHP_SELF'], 'wp-admin/' ) !== false ) {
-				unset( $error, $_GET['error'] );
+				unset( $error );
 
 				if ( isset( $perma_query_vars ) && strpos( $_SERVER['PHP_SELF'], 'wp-admin/' ) !== false ) {
 					unset( $perma_query_vars );
@@ -366,6 +366,8 @@ class WP {
 
 		if ( isset( $error ) ) {
 			$this->query_vars['error'] = $error;
+		} elseif ( ! empty( $rewrite ) ) {
+			unset( $this->query_vars['error'] );
 		}
 
 		/**
diff --git a/tests/phpunit/tests/query.php b/tests/phpunit/tests/query.php
index f6a2d28..3eb7583 100644
--- a/tests/phpunit/tests/query.php
+++ b/tests/phpunit/tests/query.php
@@ -696,4 +696,34 @@ class Tests_Query extends WP_UnitTestCase {
 		$this->assertSame( 'tax1', get_query_var( 'taxonomy' ) );
 		$this->assertSame( 'term1', get_query_var( 'term' ) );
 	}
+
+	/**
+	 * @ticket 44965
+	 */
+	public function _generate_get_vars_array() {
+		$query_str = 'state=3__5e4e4d4c9df8e6948a33fdfb44f75c0f&error=access_denied&error_description=The+user+denied+your+request';
+		parse_str($query_str, $output);
+		return $output;
+	}
+
+	public function _store_get_vars_in_global_variable() {
+		global $get_vars;
+		$get_vars = $_GET;
+	}
+
+	public function _set_get_vars_for_test_case() {
+		$_GET = $this->_generate_get_vars_array();
+		return TRUE;
+	}
+
+	public function test_query_vars_strip_error_occasionally() {
+		add_filter( 'do_parse_request', array( $this, '_set_get_vars_for_test_case' ), 11, 3 );
+		add_action( 'parse_request', array( $this, '_store_get_vars_in_global_variable' ), 11 );
+		
+		// Trigger the hooks by going to an url
+		$this->go_to( '' );
+		global $get_vars;
+
+		$this->assertSame( $get_vars, $this->_generate_get_vars_array() );
+	}
 }
