Darwin's idea was two-fold. He held that man inherited his social instincts (on which morality is built) from the lower animals; and he thought that very likely the origin of the social instinct in animals was the relation of the parents to their young. Let us first see what Darwin said.
In Chapter Four of The Descent of Man Darwin deals with "moral sense." After remarking that, so far as he knows, no one has approached the question exclusively from the side of natural history, Darwin goes on:
The following proposition seems to me in a high degree probable—namely, that any animal whatever, endowed with well-marked social instincts, the parental and filial affections being here included, would inevitably acquire a moral sense, or conscience, as soon as its intellectual powers had become as well, or nearly as well, developed as in man.
For, firstly, the social instincts lead an animal to take pleasure in the society of its fellows, and feel a certain amount of sympathy with them, and to perform various services for them....
Every one must have noticed how miserable dogs, horses, sheep, etc., are when separated from their companions, and what strong mutual affection the two former kinds, at least, shown on their reunion....
All animals living in a body, which defend themselves or attack their enemies in concert, must indeed be in some degree faithful to one another; and those that follow a leader must be in some degree obedient. When the baboons in Abyssinia plunder a garden, they silently follow a leader, and if an imprudent young animal makes a noise, he receives a slap from the others to teach him silence and obedience....
With respect to the impulse which leads certain animals to associate together, and to aid one another in many ways, we may infer that in most cases they are impelled by the same sense of satisfaction or pleasure which they experience in performing other instinctive actions....
In however complex a manner this feeling (sympathy) may have originated, as it is one of high importance to all those animals which aid and defend one another, it will have been increased through natural selection for those communities which included the greatest number of sympathetic members would flourish best and rear the greatest number of offspring....
Thus the social instincts, which must have been acquired by man in a very rude state, and probably even by his early apelike progenitors, still give the impulse to some of his best actions; but his actions are in a higher degree determined by the expressed wishes and judgment of his fellow-men, and unfortunately very often by his own strong selfish desires.
Those quotations should be enough to show Darwin's idea of the origin of the social, or moral, feelings. But I shall quote besides Haeckel's comment on Darwin's theory.