diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result
index 1f38e38..c56597e 100644
--- a/mysql-test/r/sp-error.result
+++ b/mysql-test/r/sp-error.result
@@ -779,7 +779,7 @@ drop procedure bug11394|
 CREATE PROCEDURE BUG_12490() HELP CONTENTS;
 ERROR 0A000: HELP is not allowed in stored procedures
 CREATE FUNCTION BUG_12490() RETURNS INT HELP CONTENTS;
-ERROR 0A000: HELP is not allowed in stored procedures
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'HELP CONTENTS' at line 1
 CREATE TABLE t_bug_12490(a int);
 CREATE TRIGGER BUG_12490 BEFORE UPDATE ON t_bug_12490 FOR EACH ROW HELP CONTENTS;
 ERROR 0A000: HELP is not allowed in stored procedures
diff --git a/mysql-test/suite/funcs_1/r/storedproc.result b/mysql-test/suite/funcs_1/r/storedproc.result
index f0e1ee7..655a5d3 100644
--- a/mysql-test/suite/funcs_1/r/storedproc.result
+++ b/mysql-test/suite/funcs_1/r/storedproc.result
@@ -3816,7 +3816,7 @@ return 1' at line 1
 CREATE FUNCTION fn1(a char) returns int lang sql return 1;
 ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sql return 1' at line 1
 CREATE FUNCTION fn1(a char) returns int deterministic( return 1);
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'return 1)' at line 1
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '( return 1)' at line 1
 CREATE FUNCTION fn1(a char) returns int non deterministic return 1;
 ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'deterministic return 1' at line 1
 CREATE FUNCTION fn1(a char) returns int not deterministic comment 'abc' language sql sql security refiner return 1;
diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test
index a47fbe7..d403b19 100644
--- a/mysql-test/t/sp-error.test
+++ b/mysql-test/t/sp-error.test
@@ -1093,7 +1093,7 @@ delimiter ;|
 #
 --error ER_SP_BADSTATEMENT
 CREATE PROCEDURE BUG_12490() HELP CONTENTS;
---error ER_SP_BADSTATEMENT
+--error ER_PARSE_ERROR
 CREATE FUNCTION BUG_12490() RETURNS INT HELP CONTENTS;
 CREATE TABLE t_bug_12490(a int);
 --error ER_SP_BADSTATEMENT
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index bd2adc3..18980b3 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1018,10 +1018,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
 %parse-param { THD *thd }
 %lex-param { THD *thd }
 /*
-  Currently there are 160 shift/reduce conflicts.
+  Currently there are 121 shift/reduce conflicts.
   We should not introduce new conflicts any more.
 */
-%expect 160
+%expect 121
 
 /*
    Comments for TOKENS.
@@ -1950,6 +1950,7 @@ END_OF_INPUT
 
 %type <NONE> call sp_proc_stmts sp_proc_stmts1 sp_proc_stmt
 %type <NONE> sp_proc_stmt_statement sp_proc_stmt_return
+             sp_proc_stmt_in_returns_clause
 %type <NONE> sp_proc_stmt_compound_ok
 %type <NONE> sp_proc_stmt_if
 %type <NONE> sp_labeled_control sp_unlabeled_control
@@ -2062,10 +2063,18 @@ opt_end_of_input:
         | END_OF_INPUT
         ;
 
+/*
+  binlog_base64_event is inside "verb_clause" rather than "statement".
+  This makes it impossible to use in a stored routine.
+  If we ever want to use it in SP, it should me moved from "verb_clause"
+  to "statement", and BINLOG_SYM should be removed from "keyword_sp".
+  Note, this will make impossible to use "BINLOG" as an SP label though.
+*/
 verb_clause:
           statement
         | begin
         | compound_statement
+        | binlog_base64_event
         ;
 
 /* Verb clauses, except begin and compound_statement */
@@ -2073,7 +2082,6 @@ statement:
           alter
         | analyze
         | analyze_stmt_command
-        | binlog_base64_event
         | call
         | change
         | check
@@ -3676,18 +3684,33 @@ sp_opt_default:
         | DEFAULT expr { $$ = $2; }
         ;
 
-sp_proc_stmt:
-          sp_proc_stmt_statement
-        | sp_proc_stmt_return
+/*
+  ps_proc_stmt_in_returns_clause is a statement that is allowed in the RETURNS
+  clause of a stored function definition.
+  It should not include parenthesized statements, like subselects. Otherwise,
+  the grammar generates shift/reduce conflicts for a statement like this:
+    CREATE FUNCTION f1() RETURNS CHAR (...) ...
+  After scanning CHAR followed by '(', the parser has ambiguity between:
+    CREATE FUNCTION f1() RETURNS CHAR (1) RETURN 'a';
+  and
+    CREATE FUNCTION f1() RETURNS CHAR (SELECT 1);
+*/
+sp_proc_stmt_in_returns_clause:
+          sp_proc_stmt_return
         | sp_labeled_block
         | sp_unlabeled_block
         | sp_labeled_control
+        | sp_proc_stmt_compound_ok
+        ;
+
+sp_proc_stmt:
+          sp_proc_stmt_in_returns_clause
+        | sp_proc_stmt_statement
         | sp_proc_stmt_leave
         | sp_proc_stmt_iterate
         | sp_proc_stmt_open
         | sp_proc_stmt_fetch
         | sp_proc_stmt_close
-        | sp_proc_stmt_compound_ok
         ;
 
 sp_proc_stmt_compound_ok:
@@ -16417,7 +16440,7 @@ sf_tail:
 
             lex->sphead->set_body_start(thd, lip->get_cpp_tok_start());
           }
-          sp_proc_stmt /* $15 */
+          sp_proc_stmt_in_returns_clause /* $15 */
           {
             LEX *lex= thd->lex;
             sp_head *sp= lex->sphead;
