diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php
index 5846844..723547f 100644
--- src/wp-includes/taxonomy.php
+++ src/wp-includes/taxonomy.php
@@ -2447,34 +2447,20 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) {
 
 	$term_group = 0;
 	if ( $args['alias_of'] ) {
-		$alias = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $args['alias_of'] ) );
-		if ( $alias->term_group ) {
+		$alias = get_term_by( 'slug', $args['alias_of'], $taxonomy );
+		if ( ! empty( $alias->term_group ) ) {
 			// The alias we want is already in a group, so let's use that one.
 			$term_group = $alias->term_group;
-		} else {
-			// The alias isn't in a group, so let's create a new one and firstly add the alias term to it.
-			$term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1;
-
-			/**
-			 * Fires immediately before the given terms are edited.
-			 *
-			 * @since 2.9.0
-			 *
-			 * @param int    $term_id  Term ID.
-			 * @param string $taxonomy Taxonomy slug.
+		} else if ( ! empty( $alias->term_id ) ) {
+			/*
+			 * The alias is not in a group, so we create a new one
+			 * and add the alias to it.
 			 */
-			do_action( 'edit_terms', $alias->term_id, $taxonomy );
-			$wpdb->update($wpdb->terms, compact('term_group'), array('term_id' => $alias->term_id) );
+			$term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1;
 
-			/**
-			 * Fires immediately after the given terms are edited.
-			 *
-			 * @since 2.9.0
-			 *
-			 * @param int    $term_id  Term ID
-			 * @param string $taxonomy Taxonomy slug.
-			 */
-			do_action( 'edited_terms', $alias->term_id, $taxonomy );
+			wp_update_term( $alias->term_id, $taxonomy, array(
+				'term_group' => $term_group,
+			) );
 		}
 	}
 
@@ -2959,20 +2945,20 @@ function wp_update_term( $term_id, $taxonomy, $args = array() ) {
 
 	$term_group = isset( $parsed_args['term_group'] ) ? $parsed_args['term_group'] : 0;
 	if ( $args['alias_of'] ) {
-		$alias = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $args['alias_of'] ) );
-		if ( $alias->term_group ) {
+		$alias = get_term_by( 'slug', $args['alias_of'], $taxonomy );
+		if ( ! empty( $alias->term_group ) ) {
 			// The alias we want is already in a group, so let's use that one.
 			$term_group = $alias->term_group;
-		} else {
-			// The alias isn't in a group, so let's create a new one and firstly add the alias term to it.
+		} else if ( ! empty( $alias->term_id ) ) {
+			/*
+			 * The alias is not in a group, so we create a new one
+			 * and add the alias to it.
+			 */
 			$term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1;
 
-			/** This action is documented in wp-includes/taxonomy.php */
-			do_action( 'edit_terms', $alias->term_id, $taxonomy );
-			$wpdb->update( $wpdb->terms, compact('term_group'), array( 'term_id' => $alias->term_id ) );
-
-			/** This action is documented in wp-includes/taxonomy.php */
-			do_action( 'edited_terms', $alias->term_id, $taxonomy );
+			wp_update_term( $alias->term_id, $taxonomy, array(
+				'term_group' => $term_group,
+			) );
 		}
 
 		$parsed_args['term_group'] = $term_group;
@@ -3004,7 +2990,14 @@ function wp_update_term( $term_id, $taxonomy, $args = array() ) {
 			return new WP_Error('duplicate_term_slug', sprintf(__('The slug &#8220;%s&#8221; is already in use by another term'), $slug));
 	}
 
-	/** This action is documented in wp-includes/taxonomy.php */
+	/**
+	 * Fires immediately before the given terms are edited.
+	 *
+	 * @since 2.9.0
+	 *
+	 * @param int    $term_id  Term ID.
+	 * @param string $taxonomy Taxonomy slug.
+	 */
 	do_action( 'edit_terms', $term_id, $taxonomy );
 	$wpdb->update($wpdb->terms, compact( 'name', 'slug', 'term_group' ), compact( 'term_id' ) );
 	if ( empty($slug) ) {
@@ -3012,7 +3005,14 @@ function wp_update_term( $term_id, $taxonomy, $args = array() ) {
 		$wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) );
 	}
 
-	/** This action is documented in wp-includes/taxonomy.php */
+	/**
+	 * Fires immediately after the given terms are edited.
+	 *
+	 * @since 2.9.0
+	 *
+	 * @param int    $term_id  Term ID
+	 * @param string $taxonomy Taxonomy slug.
+	 */
 	do_action( 'edited_terms', $term_id, $taxonomy );
 
 	$tt_id = $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id) );
diff --git tests/phpunit/tests/term.php tests/phpunit/tests/term.php
index 180e87d..f7d8615 100644
--- tests/phpunit/tests/term.php
+++ tests/phpunit/tests/term.php
@@ -417,6 +417,62 @@ class Tests_Term extends WP_UnitTestCase {
 		$this->assertFalse( is_wp_error( $term20 ) );
 	}
 
+	public function test_wp_insert_term_alias_of_no_term_group() {
+		register_taxonomy( 'wptests_tax', 'post' );
+		$t1 = $this->factory->term->create( array(
+			'taxonomy' => 'wptests_tax',
+		) );
+		$term_1 = get_term( $t1, 'wptests_tax' );
+
+		$created_term_ids = wp_insert_term( 'Foo', 'wptests_tax', array(
+			'alias_of' => $term_1->slug,
+		) );
+		$created_term = get_term( $created_term_ids['term_id'], 'wptests_tax' );
+
+		$updated_term_1 = get_term( $term_1->term_id, 'wptests_tax' );
+
+		$term = get_term( $created_term_ids['term_id'], 'wptests_tax' );
+		_unregister_taxonomy( 'wptests_tax' );
+
+		$this->assertSame( 0, $term_1->term_group );
+		$this->assertNotEmpty( $created_term->term_group );
+		$this->assertSame( $created_term->term_group, $updated_term_1->term_group );
+	}
+
+	public function test_wp_insert_term_alias_of_existing_term_group() {
+		register_taxonomy( 'wptests_tax', 'post' );
+		$t1 = $this->factory->term->create( array(
+			'taxonomy' => 'wptests_tax',
+		) );
+		$term_1 = get_term( $t1, 'wptests_tax' );
+
+		$t2 = $this->factory->term->create( array(
+			'taxonomy' => 'wptests_tax',
+			'alias_of' => $term_1->slug,
+		) );
+		$term_2 = get_term( $t2, 'wptests_tax' );
+
+		$created_term_ids = wp_insert_term( 'Foo', 'wptests_tax', array(
+			'alias_of' => $term_2->slug,
+		) );
+		$created_term = get_term( $created_term_ids['term_id'], 'wptests_tax' );
+		_unregister_taxonomy( 'wptests_tax' );
+
+		$this->assertNotEmpty( $created_term->term_group );
+		$this->assertSame( $created_term->term_group, $term_2->term_group );
+	}
+
+	public function test_wp_insert_term_alias_of_nonexistent_term() {
+		register_taxonomy( 'wptests_tax', 'post' );
+		$created_term_ids = wp_insert_term( 'Foo', 'wptests_tax', array(
+			'alias_of' => 'foo',
+		) );
+		$created_term = get_term( $created_term_ids['term_id'], 'wptests_tax' );
+		_unregister_taxonomy( 'wptests_tax' );
+
+		$this->assertSame( 0, $created_term->term_group );
+	}
+
 	public function test_wp_insert_term_duplicate_name_slug_non_hierarchical() {
 		register_taxonomy( 'foo', 'post', array() );
 
@@ -537,6 +593,62 @@ class Tests_Term extends WP_UnitTestCase {
 		$this->assertTrue( in_array( $found['term_id'], $cached_children[ $t ] ) );
 	}
 
+	public function test_wp_update_term_alias_of_no_term_group() {
+		register_taxonomy( 'wptests_tax', 'post' );
+		$t1 = $this->factory->term->create( array(
+			'taxonomy' => 'wptests_tax',
+		) );
+		$term_1 = get_term( $t1, 'wptests_tax' );
+
+		$created_term_ids = wp_insert_term( 'Foo', 'wptests_tax' );
+		wp_update_term( $created_term_ids['term_id'], 'wptests_tax', array(
+			'alias_of' => $term_1->slug,
+		) );
+		$created_term = get_term( $created_term_ids['term_id'], 'wptests_tax' );
+
+		$updated_term_1 = get_term( $t1, 'wptests_tax' );
+		_unregister_taxonomy( 'wptests_tax' );
+
+		$this->assertSame( 0, $term_1->term_group );
+		$this->assertNotEmpty( $created_term->term_group );
+		$this->assertSame( $created_term->term_group, $updated_term_1->term_group );
+	}
+
+	public function test_wp_update_term_alias_of_existing_term_group() {
+		register_taxonomy( 'wptests_tax', 'post' );
+		$t1 = $this->factory->term->create( array(
+			'taxonomy' => 'wptests_tax',
+		) );
+		$term_1 = get_term( $t1, 'wptests_tax' );
+
+		$t2 = $this->factory->term->create( array(
+			'taxonomy' => 'wptests_tax',
+			'alias_of' => $term_1->slug,
+		) );
+		$term_2 = get_term( $t2, 'wptests_tax' );
+
+		$created_term_ids = wp_insert_term( 'Foo', 'wptests_tax' );
+		wp_update_term( $created_term_ids['term_id'], 'wptests_tax', array(
+			'alias_of' => $term_2->slug,
+		) );
+		$created_term = get_term( $created_term_ids['term_id'], 'wptests_tax' );
+		_unregister_taxonomy( 'wptests_tax' );
+
+		$this->assertNotEmpty( $created_term->term_group );
+		$this->assertSame( $created_term->term_group, $term_2->term_group );
+	}
+
+	public function test_wp_update_term_alias_of_nonexistent_term() {
+		register_taxonomy( 'wptests_tax', 'post' );
+		$created_term_ids = wp_insert_term( 'Foo', 'wptests_tax' );
+		wp_update_term( $created_term_ids['term_id'], 'wptests_tax', array(
+			'alias_of' => 'bar',
+		) );
+		$created_term = get_term( $created_term_ids['term_id'], 'wptests_tax' );
+		_unregister_taxonomy( 'wptests_tax' );
+
+		$this->assertSame( 0, $created_term->term_group );
+	}
 	/**
 	 * @ticket 5381
 	 */
