diff --git src/wp-admin/js/customize-widgets.js src/wp-admin/js/customize-widgets.js
index 48ba335..448b13d 100644
--- src/wp-admin/js/customize-widgets.js
+++ src/wp-admin/js/customize-widgets.js
@@ -1614,7 +1614,7 @@
 				widgetNumber = widget.get( 'multi_number' );
 			}
 
-			controlHtml = $( '#widget-tpl-' + widget.get( 'id' ) ).html();
+			controlHtml = $.trim( $( '#widget-tpl-' + widget.get( 'id' ) ).html() );
 			if ( widget.get( 'is_multi' ) ) {
 				controlHtml = controlHtml.replace( /<[^<>]+>/g, function( m ) {
 					return m.replace( /__i__|%i%/g, widgetNumber );
diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php
index 18a1d76..8ed4e69 100644
--- src/wp-includes/class-wp-customize-manager.php
+++ src/wp-includes/class-wp-customize-manager.php
@@ -575,6 +575,7 @@ final class WP_Customize_Manager {
 			// to operate properly.
 			$this->stop_previewing_theme();
 			switch_theme( $this->get_stylesheet() );
+			update_option( 'theme_switched_via_customizer', true );
 			$this->start_previewing_theme();
 		}
 
diff --git src/wp-includes/class-wp-customize-widgets.php src/wp-includes/class-wp-customize-widgets.php
index 72ff397..0504df4 100644
--- src/wp-includes/class-wp-customize-widgets.php
+++ src/wp-includes/class-wp-customize-widgets.php
@@ -316,6 +316,40 @@ final class WP_Customize_Widgets {
 	}
 
 	/**
+	 * Get sidebar configuration
+	 *
+	 * Fetch the sidebar configuration directly from the option so that any preview filters are applied and 
+	 * when the customizer is loaded with a theme that is not active override the initial sidebar in the configuration
+	 * that would be applied if the theme was activated instead of being previewed.
+	 *
+	 * @since 3.9
+	 * @access public
+	 */
+	public function get_sidebars_widgets() {
+		global $sidebars_widgets;
+
+		$sidebars_widgets = get_option( 'sidebars_widgets', array() );
+
+		if ( ! $this->manager->is_preview() &&
+			( ( is_admin() && ! defined( 'DOING_AJAX' ) ) ||
+			// Only override with widgets from theme_mods when loading the initial iframe
+			( isset( $_POST['customize_messenger_channel'] ) && $_POST['customize_messenger_channel'] === 'preview-0' ) ) ) {
+
+			if ( ! isset( $this->sidebars_widgets ) ) {
+				// Cache the modified version to avoid manipulating the set of widgets a second time
+				$this->sidebars_widgets = retrieve_widgets( true, false );
+			}
+
+			// Override the widgets as fetched from the option
+			$sidebars_widgets = $this->sidebars_widgets;
+		}
+
+		unset( $sidebars_widgets['array_version'] );
+
+		return $sidebars_widgets;
+	}
+
+	/**
 	 * Register customizer settings and controls for all sidebars and widgets.
 	 *
 	 * @since 3.9.0
@@ -327,7 +361,7 @@ final class WP_Customize_Widgets {
 		$sidebars_widgets = array_merge(
 			array( 'wp_inactive_widgets' => array() ),
 			array_fill_keys( array_keys( $GLOBALS['wp_registered_sidebars'] ), array() ),
-			wp_get_sidebars_widgets()
+			$this->get_sidebars_widgets()
 		);
 
 		$new_setting_ids = array();
@@ -891,9 +925,8 @@ final class WP_Customize_Widgets {
 	 * @param array $sidebars_widgets List of widgets for the current sidebar.
 	 */
 	public function preview_sidebars_widgets( $sidebars_widgets ) {
-		$sidebars_widgets = get_option( 'sidebars_widgets' );
+		$sidebars_widgets = $this->get_sidebars_widgets();
 
-		unset( $sidebars_widgets['array_version'] );
 		return $sidebars_widgets;
 	}
 
diff --git src/wp-includes/theme.php src/wp-includes/theme.php
index f66fd95..9bb1a1f 100644
--- src/wp-includes/theme.php
+++ src/wp-includes/theme.php
@@ -1791,6 +1791,11 @@ function check_theme_switched() {
 	if ( $stylesheet = get_option( 'theme_switched' ) ) {
 		$old_theme = wp_get_theme( $stylesheet );
 
+		if ( get_option( 'theme_switched_via_customizer' ) ) {
+			remove_filter( 'after_switch_theme', '_wp_sidebars_changed' );
+			update_option( 'theme_switched_via_customizer', false );
+		}
+
 		if ( $old_theme->exists() ) {
 			/**
 			 * Fires on the first WP load after a theme switch if the old theme still exists.
@@ -1918,4 +1923,4 @@ function wp_customize_support_script() {
 		}());
 	</script>
 	<?php
-}
\ No newline at end of file
+}
diff --git src/wp-includes/widgets.php src/wp-includes/widgets.php
index b911fde..1f60a55 100644
--- src/wp-includes/widgets.php
+++ src/wp-includes/widgets.php
@@ -1402,7 +1402,7 @@ function _wp_sidebars_changed() {
 }
 
 // look for "lost" widgets, this has to run at least on each theme change
-function retrieve_widgets($theme_changed = false) {
+function retrieve_widgets($theme_changed = false, $update = true ) {
 	global $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets;
 
 	$registered_sidebar_keys = array_keys( $wp_registered_sidebars );
@@ -1412,7 +1412,10 @@ function retrieve_widgets($theme_changed = false) {
 	if ( is_array( $old_sidebars_widgets ) ) {
 		// time() that sidebars were stored is in $old_sidebars_widgets['time']
 		$_sidebars_widgets = $old_sidebars_widgets['data'];
-		remove_theme_mod( 'sidebars_widgets' );
+
+		if ( $update ) {
+			remove_theme_mod( 'sidebars_widgets' );
+		}
 
 		foreach ( $_sidebars_widgets as $sidebar => $widgets ) {
 			if ( 'wp_inactive_widgets' == $sidebar || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) )
@@ -1495,7 +1498,9 @@ function retrieve_widgets($theme_changed = false) {
 	}
 
 	$sidebars_widgets['wp_inactive_widgets'] = array_merge($lost_widgets, (array) $sidebars_widgets['wp_inactive_widgets']);
-	wp_set_sidebars_widgets($sidebars_widgets);
+	if ( $update ) {
+		wp_set_sidebars_widgets($sidebars_widgets);
+	}
 
 	return $sidebars_widgets;
 }
