Imperfect replication, competition and LOTS of time. Whenever I contemplate how something got to be that way I always come back to considering the span of time. We can easily envision the passage of a hundred yrs. maybe even a thousand. But 10,000? or 100,000 yrs?
Just a mind-numbingly slow accumulation of useful bits.