diff --git a/include/asterisk/config.h b/include/asterisk/config.h
index 98cd71445cb181ee83bd6d67b40a90ff8ff08712..0919a58bcc070fff9a7e7d9bee5139996d58caab 100644
--- a/include/asterisk/config.h
+++ b/include/asterisk/config.h
@@ -257,6 +257,10 @@ char *ast_category_browse(struct ast_config *config, const char *prev_name);
  *
  * \retval ast_variable list on success
  * \retval NULL on failure
+ *
+ * \note ast_category_browse is not thread safe and it is not safe to call
+ * ast_category_delete while browsing using ast_category_browse.
+ * ast_category_browse_filtered does not have these restrictions.
  */
 struct ast_variable *ast_variable_browse_filtered(const struct ast_config *config,
 	const char *category_name, const char *filter);
@@ -794,6 +798,9 @@ int ast_category_insert(struct ast_config *config, struct ast_category *cat, con
  * \param category category to delete
  *
  * \return the category after the deleted one which could be NULL.
+ *
+ * \note It is not safe to call ast_category_delete while browsing with
+ * ast_category_browse.  It is safe with ast_category_browse_filtered.
  */
 struct ast_category *ast_category_delete(struct ast_config *cfg, struct ast_category *category);
 
diff --git a/main/config.c b/main/config.c
index 7009e7d08ee44fce6e25f88e635e40ee481a329e..7e6a4d1c1655ee6199659d27003bcdfac311e32c 100644
--- a/main/config.c
+++ b/main/config.c
@@ -1336,6 +1336,10 @@ struct ast_category *ast_category_delete(struct ast_config *config,
 
 	prev = category->prev;
 
+	if (config->last_browse == category) {
+		config->last_browse = prev;
+	}
+
 	ast_category_destroy(category);
 
 	return prev;
diff --git a/tests/test_config.c b/tests/test_config.c
index b1f55c782a197aebfb9fac0f9659b7ef6ea78f5d..be4bee3d29559c7a6c51921b83a787dc6913dc81 100644
--- a/tests/test_config.c
+++ b/tests/test_config.c
@@ -395,26 +395,6 @@ AST_TEST_DEFINE(config_basic_ops)
 		}
 	}
 
-	/* Now: test0 test1 test3 test4 test2 */
-	/* Test in-flight deletion using ast_category_browse */
-	/* Delete test1 and continue */
-	cat_name = NULL;
-	for(i = 0; i < 5; i++) {
-		if (i == 2) {  /* 2 was already deleted above */
-			continue;
-		}
-		snprintf(temp, sizeof(temp), "test%d", i);
-		cat_name = ast_category_browse(cfg, cat_name);
-		cat = ast_category_get(cfg, cat_name, NULL);
-		if (strcmp(cat_name, temp)) {
-			ast_test_status_update(test, "Should have returned %s instead of %s: %d\n", temp, cat_name, i);
-			goto out;
-		}
-		if (i == 1) {
-			ast_category_delete(cfg, cat);
-		}
-	}
-
 	/* Now: test0 test3 test4 test2 */
 	/* delete the head item */
 	cat = ast_category_browse_filtered(cfg, NULL, NULL, NULL);
@@ -429,7 +409,7 @@ AST_TEST_DEFINE(config_basic_ops)
 	/* make sure head got updated to the new first element */
 	cat = ast_category_browse_filtered(cfg, NULL, NULL, NULL);
 	cat_name = ast_category_get_name(cat);
-	if (strcmp(cat_name, "test3")) {
+	if (strcmp(cat_name, "test1")) {
 		ast_test_status_update(test, "Should have returned test3 instead of %s\n", cat_name);
 		goto out;
 	}
@@ -446,6 +426,13 @@ AST_TEST_DEFINE(config_basic_ops)
 
 	/* There should now only be 2 elements in the list */
 	cat = NULL;
+	cat = ast_category_browse_filtered(cfg, NULL, cat, NULL);
+	cat_name = ast_category_get_name(cat);
+	if (strcmp(cat_name, "test1")) {
+		ast_test_status_update(test, "Should have returned test1 instead of %s\n", cat_name);
+		goto out;
+	}
+
 	cat = ast_category_browse_filtered(cfg, NULL, cat, NULL);
 	cat_name = ast_category_get_name(cat);
 	if (strcmp(cat_name, "test3")) {