Why did Korea split up into a north and a south?

north was communist south was capitalist and north attacked the south