diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index d75f765de0..d5fa83e736 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -1840,6 +1840,18 @@ xml_parse(text *data, XmlOptionType xmloption_arg,
 				res_code = xmlParseBalancedChunkMemory(doc, NULL, NULL, 0,
 													   utf8string + count,
 													   parsed_nodes);
+
+				/*
+				 * libxml2 2.13.x incorrectly returns parser errors even if
+				 * the chunk is well-balanced.  As a workaround, ignore the
+				 * return code if a node list was returned.
+				 * https://gitlab.gnome.org/GNOME/libxml2/-/issues/765
+				 */
+#if LIBXML_VERSION >= 21300
+				if (res_code > 0 && parsed_nodes != NULL)
+					res_code = 0;
+#endif
+
 				if (res_code != 0 || xmlerrcxt->err_occurred)
 				{
 					xml_errsave(escontext, xmlerrcxt,
