Acting selflessly to help others in need was long thought to be a trait confined to mammals, in particular humans and great apes.

But a new study has found that African gray parrots volunteer assistance to both their good friends and mere acquaintances — even when there is no expectation of personal gain.

The paper, published Thursday in the journal Current Biology, advances our knowledge of the evolution of cooperation and social intelligence, said co-author Auguste von Bayern of the Max Planck Institute for Ornithology in Starnberg, Germany.

Both parrots and birds such as crows and ravens are renowned for their extraordinary problem-solving skills and are sometimes called “feathered apes.”

Alex, the famous Harvard-based African gray parrot who died in 2007, developed a vocabulary of over 100 words, could identify colors and could quantify objects up to the number six, among many other accomplishments.

But despite their impressive intelligence, earlier experiments have failed to show crows helping other crows — leading von Bayern and first author Desiree Brucks of ETH Zurich to wonder whether the same was true of parrots.

Working at the Loro Parque research station in Spain, they placed pairs of gray parrots and blue-headed macaws in boxes alongside each other with an exchange hole between the two, and a hole facing a human experimenter that was either kept open or closed.

Both parrot species quickly learned that they could exchange tokens with the experimenter for a nut treat — but only the gray parrots helped their neighbors when their own opportunity for gain was taken away.

In the first round, seven out of eight gray parrots were willing to transfer tokens in their possession to their neighbors so that their friends could feast when they could not.

The fact they did so without knowing they would later be tested in the other role showed that those giving were not expecting the favor to be returned, said von Bayern.

Significantly, the gray parrots appeared to understand the nature of the task, as opposed to acting out of playfulness. When they saw the other parrot had an opportunity for exchange, they would pass a token over — but otherwise, they would not.

And, like humans, the gray parrots appeared to favor their friends, sharing significantly more tokens with birds they had previously closely associated with, though they still gave some to acquaintances.

The experimenters did not test whether the effect would occur with perfect strangers.

It is not fully clear why the gray parrots acted “pro-socially” while the macaws did not, but the researchers suggest it may be linked to how the two species organize themselves in the wild.

African grays live in huge flocks of up to 1,200 individuals, Brucks said, and this may require greater social cognitive abilities than macaws, which live in much smaller groups of 10 to 30 individuals.

The team now wants to investigate how widespread cooperation is among the world’s 393 parrot species and examine what evolutionary pressures led to it.

They would also like to learn how exactly the birds empathize with each other and whether the level of help given is proportionate to the need of the recipient — for example, will a parrot who just had a meal receive the same level of assistance as one which is hungry?