A whole, fully functioning organ has been grown for the first time in a living animal, pointing to the possibility of lab-created replacement organs in the future.

A team from the MRC Centre for Regenerative Medicine at the University of Edinburgh grew a thymus — a gland next to the heart that produces infection fighting T cells — inside a mouse.

Their achievement, documented in the journal Nature Cell Biology, could lead to new treatments for people with weak immune systems. It might also benefit people with thymus disorders, who suffer with a lack of donors because of tissue-matching issues.

"This was a complete surprise to us," Professor Clare Blackburn, lead researcher, told BBC News.

"This is a very exciting advance and it’s also very tantalizing in terms of the wider field of regenerative diseases."

Scientists took cells from a mouse embryo and using a technique called reprogramming, converted those cells to look like thymus cells.

Those transformed cells were then placed inside mice. Once inside a mouse, they developed into a thymus, which had the same structure and functionality as a healthy adult thymus.

The researchers say they hope their technique might create cell therapies that could help bone marrow transplant patients by speeding up the rebuilding of their immune systems after surgery.

The discovery could also aid babies born with genetic conditions that prevent the proper development of their thymus.

"More research will be needed before this process can be reproduced in a safe and tightly controlled way suitable for use in humans," Dr. Rob Buckle, head of Regenerative Medicine at the MRC, said in the publication.