The explanation was given by the grandfather of modern genetics: Mendel.
How did he find out it? Here you are the history of his life:
Mendel was born in 1822 in a town which is today called Hynice, located in the Czech Republic. Quite like Darwin, Mendel was a nature enthusiast from birth; he learnt to keep bees at a young age and was a keen gardener. Mendel’s family was poor so to secure a good future he joined an Augustinian Abbey in 1843 where he trained for priesthood. He was ordained and for a while taught in a local school. In 1851 Mendel went to the University of Vienna where he mostly studied physics before returning to the abbey.
It was at the abbey that Mendel began his famous experiments on peas. In 1854 he obtained 34 varieties of pea from local growers from which he identified seven "characters" which showed discontinuous variation:
1.flower position: terminal or axial
2.flower colour: white or purple
3.plant height: tall or short
4.pea shape: round or wrinkled
5.pea colour: yellow or green
6.pod shape: inflated or constricted
7.pod colour: yellow or green
He experimented with crossing the pairs of peas and recording what characteristics the following generation had. He would cross the offspring too, and performed a range of different experiments. After eight years he summed up his results and made his conclusions. These are now known as Mendel’s Laws.
Mendel’s results are now summarised into the Law of Segregation and the Law of Independent Assortment. In modern terms the Law of Segregation states that each individual has two copies of the information, or "gene", that produces a certain characteristic. These two copies are now called alleles, and the offspring receives one allele (only) from each of its parents. The Law of Independent Assortment states that there is no mixing between the genes for different characteristics; they remain separate entities. Mendel also concluded that one of the two alleles is always dominant over the other. Of course this is not the language Mendel used, as he had no concept of a gene or allele, but he explained his results beautifully and clearly so that the implications were there for the scientific society to see.
Mendel presented his results in 1865 to the Brünn Society for Natural Science, titling his paper Experiments in Plant Hybridisation (but in German). Little attention was taken.
Later in Mendel’s life he became a major figure at his monastery so had less time for experimentation, though he did try breeding bees and some other plant species. He died in 1884 having made little impact on the scientific world.
It was not until 1900 that Mendel's work was rediscovered, by Carl Correns in Germany, Hugo de Vries in the Netherlands and Erich von Tschermak-Seysenegg in Austria. Later that year William Bateson heard of the discovery and spread the word and began advancing, applying and improving upon Mendel’s work.