The southern states seceded, organized their own government, and forced the surrender of Fort Sumter. That’s what precipitated the war. The war was fought first to preserve the Union. But the war did settle the issue of slavery within the Union.
The North went to war to preserve the Union and won. The South went to war to preserve an economic system based on the use of slave labor and lost everything.