How about, a much more expensive Invasion of Mexico. The U.S. still wins, and gains pretty much the same OTL territory, but finds itself overextended, while anti-slavery reaction to the war has grown fierce enough that the government essentially can't get anything done.
Maybe, this is combined with hostilities with Britain over the Oregon Territory just a few years earlier, which cost the government a lot of money. That war ended in a truce, where the U.S. was forced to compromise on a little bit less land than OTL.
Thus, for about a decade or two after 1848, the most the military can do is just enforce their claims on the west to prevent others from taking it back. A gold rush still occurs, but immigration to California and other parts of the west is rather mismanaged. California and Oregon remain with a territorial status, along with Utah, and the rest of the lands remain unorganized. The settlers in the west find themselves essentially having to take care of organizing their governments themselves. The Mormons play a big part in this.
Then, when an Alternate Civil War erupts in the east, the Westerners find themselves even more separated, as most of what there is of the Union army has to be pulled back to the east. A few confederate troops invade, and the California and Mormon Militia fights them off, no thanks to the east coast who only send a few "Good luck" letters in response to requests for aid.
Finally, frustrated with the lack of attention... not sure if territories could be seen as seceding, but that is essentially what California and Oregon do, declaring themselves Free States, and quickly join into a union for mutual protection of their interests. Popular movements in the unorganized territories form rump governments which quickly declare Independence from both the U.S. and the C.S. and announce their intentions to join the Free States of America. Many of the few military garrisons that remain find themselves either surrendering to the local militias who outnumber them, or even joining them.
The Mormons also declare independence from the U.S., but quickly see that they can't really make it on their own in their territory, so they also join up with the FSA, under condition of certain autonomy and religious freedoms, built into the FSA constitution, which the government in Sacramento is quite happy to agree to. The FSA constitution also includes an article specifically stating that slavery is illegal.
The borders of the FSA are essentially the northern Rio Grande, followed by the Rockies. I don't know what's happening in the Great Plains, as the settlement of Kansas, etc. has probably been completely changed by the events above. I'm assuming that Texas remains part of the CSA, although there are no doubt some secession movements within it which would prefer to join the FSA.