Israel and Hamas have agreed a deal for the release of Sgt Gilad Shalit, an Israeli soldier held hostage by Palestinian militants for five years.
Prime Minister Benjamin Netanyahu said the deal had been reached after arduous talks, and that Sgt Shalit would be back with his family "within days".
Israel will release hundreds of Palestinian prisoners in exchange.
Sgt Shalit was captured in a cross-border raid in 2006, and attempts to negotiate his release have failed.
Mr Netanyahu said in a national TV address: "We have concluded arduous negotiations with Hamas to release Gilad Shalit. He will be coming home in the next few days."
Sgt Shalit's continued detention is a hugely emotive issue in Israel, where his family have maintained a high profile campaign for his release.
However, there are many Israelis who have had family members killed by Palestinian militants and object in principle to any mass release of prisoners.
Several high-profile Palestinian prisoners have been excluded from the release deal, a senior Israeli offical said.
The deal was confirmed in the Israeli cabinet by a 26-3 vote, following a heated three-hour debate.
"This is a difficult decision, but leadership is tested at moments like this, on the ability to make difficult decisions," said Mr Netanyahu said in a statement.
'Window of opportunity'
The militant group Hamas, which runs Gaza, said in a statement that there were tens of thousands of people on the streets celebrating the deal.
Witnesses described celebratory crowds firing guns into the air and honking car horns.
The group's leader Khaled Meshaal, who is in exile in Syria, appeared on TV to hail the swap deal as a victory for the Palestinian people.
He said the Israelis had agreed to free 1,027 prisoners - including 27 women.
However, several high-profile Palestinian prisoners will not be released, Yoram Cohen, head of Israel's Shin Bet internal intelligence service, said.
Those not due for release include key Fatah leader Marwan Barghouti, Ahmed Saadat, found guilty of ordering the killing of Israel's tourism minister in 2001, and Hamas' Abdullah Barghouti.
Reports said the first 450 prisoners would be freed in the coming days, with the rest being released over the next two months.
"It is a great achievement, a qualitative success," said Mr Meshaal.
"Because of this accord, there will no longer be any women in the jails of the enemy."
He promised to carry on working to free every Palestinian prisoner held in Israeli jails.
There are about 5,000 Palestinians held by Israel - some of whom have been convicted of serious crimes, but others are being held without charge.
The BBC's Jon Donnison in Jerusalem says Sgt Shalit's family and the families of hundreds of Palestinian prisoners will not believe a deal has been done until their relatives are home.
Israel's Channel 2 TV reported that both sides had shown greater flexibility in recent talks.
Indirect talks over the 25-year-old's release have been going on for years, with Egypt and Germany mediating.
In October 2009, Hamas released a video of the soldier calling on Mr Netanyahu to do everything to free him.