OSS vs. proprietary software

How was it ever possible that OSS overtook proprietary software? Microsoft is a 223 Billion Dollar company, RedHat is only worth $5 Billion. How can something “for free” be better than something that costs thousands of dollars?