The answer to this question relates to the evolution of prokaryotic cells. The first simple prokaryotic cells likely evolved mitochondria from a cell that engulfed an aerobic prokaryotic cell, resulting in an endosymbiotic relationship, and gradual development into a mitochondrion. Something similar happened in regards to chloroplasts, except the original cell engulfed was probably a simple photosynthesising bacteria such as cyanobacteria.