diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php
index fab2640..7546f80 100644
--- a/wp-includes/category-template.php
+++ b/wp-includes/category-template.php
@@ -624,7 +624,7 @@ function wp_list_categories( $args = '' ) {
 		$output .= walk_category_tree( $categories, $depth, $r );
 	}
 
-	if ( $r['title_li'] && 'list' == $r['style'] )
+	if ( $r['title_li'] && 'list' == $r['style'] && ( ! empty( $categories ) || ! $r['hide_title_if_empty'] ) )
 		$output .= '</ul></li>';
 
 	/**
