The endosymbiotic theory is the accepted mechanism for how eukaryotic cells evolved from prokaryotic cells. First published by Lynn Margulis in the late 1960s, the Endosymbiont Theory proposed that the main organelles of the eukaryotic cell were actually primitive prokaryotic cells that had been engulfed by a different, bigger prokaryotic cell. The term "endosymbiosis" means "to cooperate inside". Whether the larger cell provided protection for the smaller cells, or the smaller cells provided energy to the larger cell, this arrangement seemed to be mutually beneficial to all of the prokaryotes.
While this sounded like a far-fetched idea at first, the data to back it up is undeniable. The organelles that seemed to have been their own cells include the mitochondria and, in photosynthetic cells, the chloroplast. Both of these organelles have their own DNA and their own ribosomes that do not match the rest of the cell. This indicates that they could survive and reproduce on their own. In fact, the DNA in the chloroplast is very similar to photosynthetic bacteria called cyanobacteria. The DNA in the mitochondria is most like that of the bacteria that causes typhus.
Before these prokaryotes were able to undergo endosymbiosis, they first most likely had to become colonial organisms. Colonial organisms are groups of prokaryotic, single-celled organisms that live in close proximity to other single-celled prokaryotes. Even though the individual single-celled organisms remained separate and could survive independently, there was some sort of advantage to living close to other prokaryotes. Whether this was a function of protection or a way to get more energy, colonialism has to be beneficial in some manner for all of the prokaryotes involved in the colony.
Once these single-celled living things were within close enough proximity to one another, they took their symbiotic relationship one step further. The larger unicellular organism engulfed other, smaller, single-celled organisms. At that point, they were no longer independent colonial organisms but instead were one large cell. When the larger cell that had engulfed the smaller cells went to divide, copies of the smaller prokaryotes inside were made and passed down to the daughter cells. Eventually, the smaller prokaryotes that had been engulfed adapted and evolved into some of the organelles we know of today in eukaryotic cells like the mitochondria and chloroplasts. Other organelles eventually arose from these first organelles, including the nucleus where the DNA in a eukaryote is housed, the endoplasmic reticulum and the Golgi Apparatus. In the modern eukaryotic cell, these parts are known as membrane-bound organelles. They still do not appear in prokaryotic cells like bacteria and archaea but are present in all organisms classified under the Eukarya domain.