It was thought Yang Guang and Tian Tian would have to return to China under the terms of the initial 10-year deal.
The zoo had been paying about £750,000 annually to China for the pandas but said that amount would be halved for the two-year extension.
It was also confirmed that breeding would not be attempted over the next two years.
In total, there have been eight unsuccessful attempts at artificial insemination, the latest one earlier this year.
David Field, the chief executive of the Royal Zoological Society Scotland (RZSS), said they were "thrilled" the 10-year contract with the Chinese government had been extended.
He said: "Yang Guang and Tian Tian have helped millions of people connect with nature, so it is fantastic that they will be with us a little longer before we say goodbye, especially as the pandemic has made it much harder for people to visit them.
"We also hope that international travel restrictions will ease over the next two years, meaning our giant panda keepers will be able to travel with Yang Guang and Tian Tian to China and help them settle into their new homes. This will be ideal as they both have strong bonds with our panda team."
Edinburgh Zoo has had financial pressures resulting from a £2m loss during Covid lockdown closures.
During the pandemic, the zoo has taken a government loan, furloughed staff, made redundancies and launched a fundraising appeal, but was not eligible for the UK government's zoo fund, which was aimed at smaller zoos.
The zoo is part of a number of conservation projects, including one to reintroduce Scottish wildcats.
A number of natural and artificial insemination breeding attempts between the pandas were unsuccessful, and Mr Field said "now is the time to move on".
He added: "A cub would have generated even more interest in giant pandas and given Tian Tian a wonderful opportunity to be a mother again, after she gave birth in China.
"We are very proud of the contribution we have made to giant panda breeding research alongside our partners at the University of Edinburgh and our findings have been of real benefit to international efforts to protect the species."
The RZSS said plans would now be made to convert the giant panda habitat at the zoo for a new species to arrive once Yang Guang and Tian Tian depart in 2023.
The original 10-year deal involved annual donations of $1m (about £750,000) to conservation efforts in China.
Mr Field said they would continue to make a "substantial" annual donation while the pandas remain in Edinburgh.
It was later confirmed that would be $500,000 (about £375,000).
He added: "We are facing a biodiversity crisis and it is vital that we expand our work to protect more endangered animals around the world," he said.
""Many other animals still face the threat of extinction and we are excited about working with a new species at the zoo.
"We will decide on the species over the next year, with a crucial factor being how we can support conservation in the wild."