diff --git a/mysql-test/r/sql_mode.result b/mysql-test/r/sql_mode.result
index 5492a7a65fcc7b30cb013e37af1b199dcbbd59f8..09adc48259c0d91289974ee88566b4dad652e97e 100644
--- a/mysql-test/r/sql_mode.result
+++ b/mysql-test/r/sql_mode.result
@@ -386,4 +386,18 @@ p	mask	example
 20	\\\\%	\\\\%
 20	\\\\%	\\\\_
 DROP TABLE t1;
+SET @@SQL_MODE='NO_BACKSLASH_ESCAPES';
+SELECT 'a\\b', 'a\\\"b', 'a''\\b', 'a''\\\"b';
+a\\b	a\\\"b	a'\\b	a'\\\"b
+a\\b	a\\\"b	a'\\b	a'\\\"b
+SELECT "a\\b", "a\\\'b", "a""\\b", "a""\\\'b";
+a\\b	a\\\'b	a"\\b	a"\\\'b
+a\\b	a\\\'b	a"\\b	a"\\\'b
+SET @@SQL_MODE='';
+SELECT 'a\\b', 'a\\\"b', 'a''\\b', 'a''\\\"b';
+a\b	a\"b	a'\b	a'\"b
+a\b	a\"b	a'\b	a'\"b
+SELECT "a\\b", "a\\\'b", "a""\\b", "a""\\\'b";
+a\b	a\'b	a"\b	a"\'b
+a\b	a\'b	a"\b	a"\'b
 SET @@SQL_MODE=@OLD_SQL_MODE;
diff --git a/mysql-test/t/sql_mode.test b/mysql-test/t/sql_mode.test
index fa5c6cb8a5ba765b33b54383fe894afe2842973f..e80752eb71b259259c534d057cdb6ba8c93fece5 100644
--- a/mysql-test/t/sql_mode.test
+++ b/mysql-test/t/sql_mode.test
@@ -174,4 +174,14 @@ order by masks.p, example;
 
 DROP TABLE t1;
 
+# Bug #6368: Make sure backslashes mixed with doubled quotes are handled
+# correctly in NO_BACKSLASH_ESCAPES mode
+SET @@SQL_MODE='NO_BACKSLASH_ESCAPES';
+SELECT 'a\\b', 'a\\\"b', 'a''\\b', 'a''\\\"b';
+SELECT "a\\b", "a\\\'b", "a""\\b", "a""\\\'b";
+
+SET @@SQL_MODE='';
+SELECT 'a\\b', 'a\\\"b', 'a''\\b', 'a''\\\"b';
+SELECT "a\\b", "a\\\'b", "a""\\b", "a""\\\'b";
+
 SET @@SQL_MODE=@OLD_SQL_MODE;
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 43e82ff57c94c48b58d5f9f86e42c82a5c49c01f..7255b0aa64f22e60f82ba01c13ee25ccef904af6 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -334,7 +334,8 @@ static char *get_text(LEX *lex)
 	      continue;
 	  }
 #endif
-	  if (*str == '\\' && str+1 != end)
+	  if (!(lex->thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) &&
+              *str == '\\' && str+1 != end)
 	  {
 	    switch(*++str) {
 	    case 'n':