IIRC, MS contracted with IBM to develop DOS. Somewhere along the line, IBM decided to ditch the Personal Computer, and more or less gave MS the rights to DOS.
The rest is history.
And in doing so set a new standard by which all terrible business decisions are measured. The old standard was Ford's Edsel, but IBM blew the doors off the Edsel decision with it's bone headed move to blow off PC Operating systems.