diff --git src/wp-admin/customize.php src/wp-admin/customize.php
index d6cec32..a858c25 100644
--- src/wp-admin/customize.php
+++ src/wp-admin/customize.php
@@ -252,6 +252,7 @@ do_action( 'customize_controls_print_scripts' );
 		$settings['settings'][ $id ] = array(
 			'value'     => $setting->js_value(),
 			'transport' => $setting->transport,
+			'dirty'     => $setting->dirty,
 		);
 	}
 
diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js
index d95287c..ccce08e 100644
--- src/wp-admin/js/customize-controls.js
+++ src/wp-admin/js/customize-controls.js
@@ -17,6 +17,7 @@
 
 			this.id = id;
 			this.transport = this.transport || 'refresh';
+			this._dirty = options.dirty || false;
 
 			this.bind( this.preview );
 		},
@@ -2424,7 +2425,8 @@
 		$.each( api.settings.settings, function( id, data ) {
 			api.create( id, id, data.value, {
 				transport: data.transport,
-				previewer: api.previewer
+				previewer: api.previewer,
+				dirty: !! data.dirty
 			} );
 		});
 
diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php
index ffdb3f3..d050345 100644
--- src/wp-includes/class-wp-customize-manager.php
+++ src/wp-includes/class-wp-customize-manager.php
@@ -695,17 +695,53 @@ final class WP_Customize_Manager {
 	 * Switch the theme and trigger the save() method on each setting.
 	 *
 	 * @since 3.4.0
+	 * @since 4.1.2 Add $options param.
+	 *
+	 * @param array $options {
+	 *      Override default behaviors for save method.
+	 *      @type bool $check_ajax_referer Whether check_ajax_referer() is performed. Defaults to true.
+	 *      @type bool $send_json Whether to return json; if false, returns WP_Error on failure, and the customize_save_response array on success. Defaults to true.
+	 * }
+	 * @return WP_Error|array|null
 	 */
-	public function save() {
+	public function save( $options = array() ) {
+		$options = array_merge(
+			array(
+				'check_ajax_referer' => true,
+				'send_json' => true,
+			),
+			empty( $options ) ? array() : $options
+		);
+
 		if ( ! $this->is_preview() ) {
-			wp_send_json_error( 'not_preview' );
+			$error = 'not_preview';
+			if ( $options['send_json'] ) {
+				wp_send_json_error( $error );
+			} else {
+				return new WP_Error( $error );
+			}
 		}
 
 		$action = 'save-customize_' . $this->get_stylesheet();
-		if ( ! check_ajax_referer( $action, 'nonce', false ) ) {
-			wp_send_json_error( 'invalid_nonce' );
+		if ( $options['check_ajax_referer'] && ! check_ajax_referer( $action, 'nonce', false ) ) {
+			$error = 'invalid_nonce';
+			if ( $options['send_json'] ) {
+				wp_send_json_error( $error );
+			} else {
+				return new WP_Error( $error );
+			}
 		}
 
+		/**
+		 * Fires before the theme has switched in the Customizer, and before settings
+		 * have been saved.
+		 *
+		 * @since 4.1.2
+		 *
+		 * @param WP_Customize_Manager $this WP_Customize_Manager instance.
+		 */
+		do_action( 'customize_save_before_switch_theme', $this );
+
 		// Do we have to switch themes?
 		if ( ! $this->is_theme_active() ) {
 			// Temporarily stop previewing the theme to allow switch_themes()
@@ -751,7 +787,11 @@ final class WP_Customize_Manager {
 		 * @param WP_Customize_Manager $this WP_Customize_Manager instance.
 		 */
 		$response = apply_filters( 'customize_save_response', array(), $this );
-		wp_send_json_success( $response );
+		if ( $options['send_json'] ) {
+			wp_send_json_success( $response );
+		} else {
+			return $response;
+		}
 	}
 
 	/**
diff --git src/wp-includes/class-wp-customize-setting.php src/wp-includes/class-wp-customize-setting.php
index 5618314..18598dc 100644
--- src/wp-includes/class-wp-customize-setting.php
+++ src/wp-includes/class-wp-customize-setting.php
@@ -60,6 +60,20 @@ class WP_Customize_Setting {
 	public $sanitize_callback    = '';
 	public $sanitize_js_callback = '';
 
+	/**
+	 * Whether or not the setting is initially dirty when created.
+	 *
+	 * This is used to ensure that a setting will be sent from the pane to the
+	 * preview when loading the Customizer. Normally a setting only is synced to
+	 * the preview if it has been changed. This allows the setting to be sent
+	 * from the start.
+	 *
+	 * @since 4.1.2
+	 * @access public
+	 * @var bool
+	 */
+	public $dirty = false;
+
 	protected $id_data = array();
 
 	/**
diff --git src/wp-includes/class-wp-customize-widgets.php src/wp-includes/class-wp-customize-widgets.php
index 674dee6..79193f9 100644
--- src/wp-includes/class-wp-customize-widgets.php
+++ src/wp-includes/class-wp-customize-widgets.php
@@ -216,6 +216,7 @@ final class WP_Customize_Widgets {
 		$sidebars_widgets = $this->old_sidebars_widgets;
 		$sidebars_widgets = retrieve_widgets( 'customize' );
 		add_filter( 'option_sidebars_widgets', array( $this, 'filter_option_sidebars_widgets_for_theme_switch' ), 1 );
+		unset( $GLOBALS['_wp_sidebars_widgets'] ); // reset global cache var used by wp_get_sidebars_widgets()
 	}
 
 	/**
@@ -232,6 +233,7 @@ final class WP_Customize_Widgets {
 	 * @access public
 	 *
 	 * @param array $old_sidebars_widgets
+	 * @return array
 	 */
 	public function filter_customize_value_old_sidebars_widgets_data( $old_sidebars_widgets ) {
 		return $this->old_sidebars_widgets;
@@ -249,6 +251,7 @@ final class WP_Customize_Widgets {
 	 * @access public
 	 *
 	 * @param array $sidebars_widgets
+	 * @return array
 	 */
 	public function filter_option_sidebars_widgets_for_theme_switch( $sidebars_widgets ) {
 		$sidebars_widgets = $GLOBALS['sidebars_widgets'];
@@ -332,6 +335,7 @@ final class WP_Customize_Widgets {
 			$setting_id = 'old_sidebars_widgets_data';
 			$setting_args = $this->get_setting_args( $setting_id, array(
 				'type' => 'global_variable',
+				'dirty' => true,
 			) );
 			$this->manager->add_setting( $setting_id, $setting_args );
 		}
@@ -356,6 +360,9 @@ final class WP_Customize_Widgets {
 				$setting_id   = sprintf( 'sidebars_widgets[%s]', $sidebar_id );
 				$setting_args = $this->get_setting_args( $setting_id );
 				if ( ! $this->manager->get_setting( $setting_id ) ) {
+					if ( ! $this->manager->is_theme_active() ) {
+						$setting_args['dirty'] = true;
+					}
 					$this->manager->add_setting( $setting_id, $setting_args );
 				}
 				$new_setting_ids[] = $setting_id;
@@ -894,6 +901,7 @@ final class WP_Customize_Widgets {
 	 * @access public
 	 *
 	 * @param array $sidebars_widgets List of widgets for the current sidebar.
+	 * @return array
 	 */
 	public function preview_sidebars_widgets( $sidebars_widgets ) {
 		$sidebars_widgets = get_option( 'sidebars_widgets' );
diff --git src/wp-includes/class-wp-theme.php src/wp-includes/class-wp-theme.php
index 523c733..41e2ca2 100644
--- src/wp-includes/class-wp-theme.php
+++ src/wp-includes/class-wp-theme.php
@@ -1121,10 +1121,7 @@ final class WP_Theme implements ArrayAccess {
 	 * @return array Array of stylesheet names.
 	 */
 	public static function get_allowed_on_network() {
-		static $allowed_themes;
-		if ( ! isset( $allowed_themes ) )
-			$allowed_themes = (array) get_site_option( 'allowedthemes' );
-		return $allowed_themes;
+		return (array) get_site_option( 'allowedthemes' );
 	}
 
 	/**
@@ -1137,7 +1134,10 @@ final class WP_Theme implements ArrayAccess {
 	 * @return array Array of stylesheet names.
 	 */
 	public static function get_allowed_on_site( $blog_id = null ) {
-		static $allowed_themes = array();
+		$allowed_themes = wp_cache_get( 'themes_allowed_on_site' );
+		if ( empty( $allowed_themes ) ) {
+			$allowed_themes = array();
+		}
 
 		if ( ! $blog_id || ! is_multisite() )
 			$blog_id = get_current_blog_id();
@@ -1191,7 +1191,9 @@ final class WP_Theme implements ArrayAccess {
 			}
 		}
 
-		return (array) $allowed_themes[ $blog_id ];
+		$allowed_on_site = (array) $allowed_themes[ $blog_id ];
+		wp_cache_set( 'themes_allowed_on_site', $allowed_on_site );
+		return $allowed_on_site;
 	}
 
 	/**
diff --git src/wp-includes/theme.php src/wp-includes/theme.php
index 3f5b5e7..1ddf221 100644
--- src/wp-includes/theme.php
+++ src/wp-includes/theme.php
@@ -762,7 +762,7 @@ function switch_theme( $stylesheet ) {
 	global $wp_theme_directories, $wp_customize, $sidebars_widgets;
 
 	$_sidebars_widgets = null;
-	if ( 'wp_ajax_customize_save' === current_action() ) {
+	if ( did_action( 'customize_save_before_switch_theme' ) ) {
 		$_sidebars_widgets = $wp_customize->post_value( $wp_customize->get_setting( 'old_sidebars_widgets_data' ) );
 	} elseif ( is_array( $sidebars_widgets ) ) {
 		$_sidebars_widgets = $sidebars_widgets;
@@ -807,7 +807,7 @@ function switch_theme( $stylesheet ) {
 		 * we need to to remove the theme mods to avoid overwriting changes made via
 		 * the Customizer when accessing wp-admin/widgets.php.
 		 */
-		if ( 'wp_ajax_customize_save' === current_action() ) {
+		if ( did_action( 'customize_save_before_switch_theme' ) ) {
 			remove_theme_mod( 'sidebars_widgets' );
 		}
 	}
diff --git tests/phpunit/includes/testcase.php tests/phpunit/includes/testcase.php
index 81f9686..a54b5e6 100644
--- tests/phpunit/includes/testcase.php
+++ tests/phpunit/includes/testcase.php
@@ -87,6 +87,7 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
 	function clean_up_global_scope() {
 		$_GET = array();
 		$_POST = array();
+		$_REQUEST = array();
 		$this->flush_cache();
 	}
 
diff --git tests/phpunit/tests/customize/setting.php tests/phpunit/tests/customize/setting.php
index a783287..bf91a7d 100644
--- tests/phpunit/tests/customize/setting.php
+++ tests/phpunit/tests/customize/setting.php
@@ -44,6 +44,7 @@ class Tests_WP_Customize_Setting extends WP_UnitTestCase {
 		$this->assertEquals( '', $setting->sanitize_js_callback );
 		$this->assertFalse( has_filter( "customize_sanitize_{$setting->id}" ) );
 		$this->assertFalse( has_filter( "customize_sanitize_js_{$setting->id}" ) );
+		$this->assertEquals( false, $setting->dirty );
 	}
 
 	function test_constructor_with_args() {
diff --git tests/phpunit/tests/customize/widgets.php tests/phpunit/tests/customize/widgets.php
index 8decbef..a7c9e40 100644
--- tests/phpunit/tests/customize/widgets.php
+++ tests/phpunit/tests/customize/widgets.php
@@ -12,6 +12,9 @@ class Tests_WP_Customize_Widgets extends WP_UnitTestCase {
 	 */
 	protected $manager;
 
+	protected $twentyfifteen_sidebars_widgets;
+	protected $twentythirteen_sidebars_widgets;
+
 	function setUp() {
 		parent::setUp();
 		require_once( ABSPATH . WPINC . '/class-wp-customize-manager.php' );
@@ -21,8 +24,15 @@ class Tests_WP_Customize_Widgets extends WP_UnitTestCase {
 		unset( $GLOBALS['_wp_sidebars_widgets'] ); // clear out cache set by wp_get_sidebars_widgets()
 		$sidebars_widgets = wp_get_sidebars_widgets();
 		$this->assertEqualSets( array( 'wp_inactive_widgets', 'sidebar-1' ), array_keys( wp_get_sidebars_widgets() ) );
-		$this->assertContains( 'search-2', $sidebars_widgets['sidebar-1'] );
-		$this->assertContains( 'categories-2', $sidebars_widgets['sidebar-1'] );
+		$initial_sidebar_1 = array(
+			'search-2',
+			'recent-posts-2',
+			'recent-comments-2',
+			'archives-2',
+			'categories-2',
+			'meta-2',
+		);
+		$this->assertEquals( $initial_sidebar_1, $sidebars_widgets['sidebar-1'] );
 		$this->assertArrayHasKey( 2, get_option( 'widget_search' ) );
 		$widget_categories = get_option( 'widget_categories' );
 		$this->assertArrayHasKey( 2, $widget_categories );
@@ -99,6 +109,184 @@ class Tests_WP_Customize_Widgets extends WP_UnitTestCase {
 	}
 
 	/**
+	 * @param string $new_theme Stylesheet
+	 *
+	 * @throws Exception
+	 */
+	function prepare_theme_switch_state( $new_theme ) {
+		$old_theme = get_stylesheet();
+		if ( 'twentyfifteen' !== $old_theme ) {
+			throw new Exception( 'Currently expecting initial theme to be twentyfifteen.' );
+		}
+		if ( $new_theme === $old_theme ) {
+			throw new Exception( 'A different theme must be supplied than the current theme.' );
+		}
+
+		// Make sure the new theme and the old theme are both among allowed themes
+		update_site_option( 'allowedthemes', array_fill_keys( array( $new_theme, $old_theme ), true ) );
+		$this->assertTrue( wp_get_theme( $old_theme )->is_allowed(), "Expected old theme $old_theme to be allowed." );
+		$this->assertTrue( wp_get_theme( $new_theme )->is_allowed(), "Expected new theme $new_theme to be allowed" );
+
+		// Set the sidebars_widgets theme mods for both the old theme and the new theme
+		$this->twentyfifteen_sidebars_widgets = wp_get_sidebars_widgets();
+		$this->twentythirteen_sidebars_widgets = $this->twentyfifteen_sidebars_widgets;
+		$this->twentythirteen_sidebars_widgets['sidebar-2'] = array();
+		for ( $i = 0; $i < 3; $i += 1 ) {
+			$this->twentythirteen_sidebars_widgets['sidebar-2'][] = array_pop( $this->twentythirteen_sidebars_widgets['sidebar-1'] );
+		}
+		$this->twentythirteen_sidebars_widgets['sidebar-1'] = array_reverse( $this->twentythirteen_sidebars_widgets['sidebar-1'] );
+		update_option( 'theme_mods_twentythirteen', array(
+			'sidebars_widgets' => array(
+				'time' => time() - 3600,
+				'data' => $this->twentythirteen_sidebars_widgets,
+			),
+		) );
+
+		$this->switch_theme_and_check_switched( $new_theme );
+		$sidebars_widgets = get_option( 'sidebars_widgets' );
+		$this->assertEquals( $this->twentythirteen_sidebars_widgets['sidebar-1'], $sidebars_widgets['sidebar-1'] );
+		$this->assertEquals( $this->twentythirteen_sidebars_widgets['sidebar-2'], $sidebars_widgets['sidebar-2'] );
+
+		$this->switch_theme_and_check_switched( $old_theme );
+		$sidebars_widgets = get_option( 'sidebars_widgets' );
+		$this->assertEquals( $this->twentyfifteen_sidebars_widgets['sidebar-1'], $sidebars_widgets['sidebar-1'] );
+	}
+
+	/**
+	 * @param string $new_theme Stylesheet
+	 *
+	 * @throws Exception
+	 */
+	function switch_theme_and_check_switched( $new_theme ) {
+		switch_theme( $new_theme );
+		$this->setup_sidebars_for_theme_switch( $new_theme );
+		check_theme_switched();
+	}
+
+	/**
+	 * Emulate loading the theme's functions.php
+	 *
+	 * @param string $new_theme stylesheet
+	 *
+	 * @throws Exception
+	 */
+	function setup_sidebars_for_theme_switch( $new_theme ) {
+		if ( 'twentythirteen' === $new_theme ) {
+			register_sidebar( array(
+				'name'          => __( 'Secondary Widget Area', 'twentythirteen' ),
+				'id'            => 'sidebar-2',
+				'description'   => __( 'Appears on posts and pages in the sidebar.', 'twentythirteen' ),
+				'before_widget' => '<aside id="%1$s" class="widget %2$s">',
+				'after_widget'  => '</aside>',
+				'before_title'  => '<h3 class="widget-title">',
+				'after_title'   => '</h3>',
+			) );
+		} else if ( 'twentyfifteen' === $new_theme ) {
+			unregister_sidebar( 'sidebar-2' );
+		} else {
+			throw new Exception( 'Only twentyfifteen and twentythirteen are supported.' );
+		}
+	}
+
+	function test_override_sidebars_widgets_for_non_theme_switch() {
+		if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
+			$this->markTestSkipped( 'The WP_Customize_Widgets::override_sidebars_widgets_for_theme_switch() method short-circuits if DOING_AJAX.' );
+		}
+		$this->do_customize_boot_actions();
+		$this->assertEmpty( $this->manager->get_setting( 'old_sidebars_widgets_data' ) );
+	}
+
+	/**
+	 * Test WP_Customize_Widgets::override_sidebars_widgets_for_theme_switch()
+	 *
+	 * @todo A lot of this should be in a test for WP_Customize_Manager::setup_theme()
+	 */
+	function test_override_sidebars_widgets_for_theme_switch() {
+		global $wpdb;
+
+		if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
+			$this->markTestSkipped( 'The WP_Customize_Widgets::override_sidebars_widgets_for_theme_switch() method short-circuits if DOING_AJAX.' );
+		}
+		$start_time = time();
+		$old_theme = get_stylesheet();
+		$new_theme = 'twentythirteen';
+		$this->assertNotEquals( $new_theme, $old_theme );
+
+		$initial_sidebars_widgets = get_option( 'sidebars_widgets' );
+		$this->prepare_theme_switch_state( $new_theme );
+		$checked_sidebars_widgets = get_option( 'sidebars_widgets' );
+		$this->assertEquals( $initial_sidebars_widgets['sidebar-1'], $checked_sidebars_widgets['sidebar-1'], 'Expected sidebar-1 to be back in initial state after round-trip theme switch.' );
+		$this->assertArrayNotHasKey( 'orphaned_widgets_1', $checked_sidebars_widgets );
+		$this->assertArrayNotHasKey( 'sidebar-2', $checked_sidebars_widgets );
+
+		// Initialize the Customizer with a preview for the new theme
+		$_REQUEST['theme'] = $new_theme;
+		add_action( 'start_previewing_theme', array( $this, 'set_up_sidebars_for_theme_preview' ) );
+		$this->do_customize_boot_actions();
+		$this->assertEquals( $new_theme, $this->manager->get_stylesheet() );
+
+		$sidebars_widgets = get_option( 'sidebars_widgets' );
+		$this->assertArrayNotHasKey( 'orphaned_widgets_1', $sidebars_widgets );
+		$this->assertEquals( $this->twentythirteen_sidebars_widgets['sidebar-1'], $sidebars_widgets['sidebar-1'] );
+		$this->assertEquals( $this->twentythirteen_sidebars_widgets['sidebar-2'], $sidebars_widgets['sidebar-2'] );
+		unset( $sidebars_widgets['array_version'] );
+		$this->assertEquals( $sidebars_widgets, wp_get_sidebars_widgets() );
+
+		$db_sidebars_widgets = maybe_unserialize( $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'sidebars_widgets'" ) );
+		$this->assertEquals( $db_sidebars_widgets['sidebar-1'], $initial_sidebars_widgets['sidebar-1'] );
+		$this->assertArrayNotHasKey( 'sidebar-2', $db_sidebars_widgets );
+
+		$old_sidebars_widgets_setting = $this->manager->get_setting( 'old_sidebars_widgets_data' );
+		$this->assertNotEmpty( $old_sidebars_widgets_setting );
+		$old_sidebars_widgets_value = $old_sidebars_widgets_setting->value();
+		$this->assertNotEmpty( $old_sidebars_widgets_value );
+		$this->assertEquals( $this->twentyfifteen_sidebars_widgets['sidebar-1'], $old_sidebars_widgets_value['sidebar-1'] );
+		$this->assertArrayNotHasKey( 'sidebar-2', $old_sidebars_widgets_value['sidebar-1'] );
+
+		$expected_dirty_settings = array( 'sidebars_widgets[sidebar-1]', 'sidebars_widgets[sidebar-2]', 'old_sidebars_widgets_data' );
+		foreach ( $expected_dirty_settings as $dirty_setting_id ) {
+			$this->assertTrue( $this->manager->get_setting( $dirty_setting_id )->dirty, "Expected setting $dirty_setting_id to be dirty." );
+		}
+
+		// Now save the customizer, and remove preview filters which interfere with saving
+		foreach ( $this->manager->settings() as $setting ) {
+			if ( $setting->dirty ) {
+				$this->manager->set_post_value( $setting->id, $setting->value() );
+				$id_base = preg_replace( '/\[.*/', '', $setting->id );
+				if ( 'theme_mod' === $setting->type ) {
+					remove_filter( "theme_mod_{$id_base}", array( $setting, '_preview_filter' ) );
+				} else if ( 'option' === $setting->type ) {
+					remove_filter( "pre_option_{$id_base}", array( $setting, '_preview_filter' ) );
+					remove_filter( "option_{$id_base}", array( $setting, '_preview_filter' ) );
+					remove_filter( "default_option_{$id_base}", array( $setting, '_preview_filter' ) );
+				}
+			}
+		}
+		remove_filter( 'option_sidebars_widgets', array( $this->manager->widgets, 'filter_option_sidebars_widgets_for_theme_switch' ), 1 );
+		$response = $this->manager->save( array( 'check_ajax_referer' => false, 'send_json' => false ) );
+		$this->assertInternalType( 'array', $response ); // and not a WP_Error
+
+		// Ensure that the new theme's sidebars have been saved as expected
+		$db_sidebars_widgets = maybe_unserialize( $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'sidebars_widgets'" ) );
+		$this->assertEquals( $this->twentythirteen_sidebars_widgets['sidebar-1'], $db_sidebars_widgets['sidebar-1'] );
+		$this->assertEquals( $this->twentythirteen_sidebars_widgets['sidebar-2'], $db_sidebars_widgets['sidebar-2'] );
+
+		// Ensure that the old theme's sidebars have been placed in that theme's widgets_sidebars theme mod
+		$old_theme_sidebars_widgets_theme_mod = get_option( "theme_mods_{$old_theme}" );
+		$this->assertEquals( $old_sidebars_widgets_value, $old_theme_sidebars_widgets_theme_mod['sidebars_widgets']['data'] );
+		$this->assertGreaterThanOrEqual( $old_theme_sidebars_widgets_theme_mod['sidebars_widgets']['time'], $start_time );
+		$new_theme_mods = get_option( "theme_mods_{$new_theme}" );
+		$this->assertEmpty( $new_theme_mods['sidebars_widgets'], "Expected new theme's sidebars_widgets theme mod to be gone." );
+	}
+
+	/**
+	 * @param WP_Customize_Manager $wp_customize
+	 */
+	function set_up_sidebars_for_theme_preview( $wp_customize ) {
+		$this->setup_sidebars_for_theme_switch( $wp_customize->get_stylesheet() );
+	}
+
+	/**
 	 * Test WP_Customize_Widgets::get_setting_args()
 	 */
 	function test_get_setting_args() {
