* Right-wing ally of Netanyahu replaces Peres as president
* Peres defends Gaza offensive, says peace still possible
* Peres' political career spanned nearly seven decades
By Allyn Fisher-Ilan
JERUSALEM, July 24 (Reuters) - Israel's elder statesman Shimon Peres bowed out of active political life on Thursday with an ardent defence of the war in Gaza against Hamas militants and a defiant prediction that peace will "one day" come to the Middle East.
At a ceremony overshadowed by the 17-day Gaza conflict in which nearly 800 people have died, Peres, 90, relinquished his largely ceremonial post as Israeli president to Reuven Rivlin, a member of Prime Minister Benjamin Netanyahu's Likud Party.
Israeli heads of state are not directly involved in political decision-making, but Peres, a Nobel Peace Laureate, has used the presidency over the last seven years as a pulpit for advocating peace with the Palestinians, often taking a more conciliatory stance than right-winger Netanyahu.
In his farewell speech, Peres invoked the biblical prophets he said had taught Israel to see "social justice and world peace as guiding principles" and he urged the Jewish state to "practise equality for all its citizens".
"I will not give up my right to serve my people and my country. And I will continue to help build my country, with a deep belief that one day it will know peace," he added, making clear he did not envisage a quiet retirement.
But Peres also defended Israel's offensive in Gaza, launched in response to rocket attacks on its territory, despite the deaths of at least 762 Palestinians and 32 Israeli soldiers. He accused Hamas militants of turning Gaza "into a man-made tragedy" and of deliberately putting civilians in harm's way.
"Israel is not the enemy of the people of Gaza," he said.
But he also said Israel should welcome and encourage debate about the rights and wrongs of the conflict in Gaza.
"In these difficult days in which the eyes of the nation are on its leaders, on you, please do not lessen the debate. It is the essence of democracy," said Peres.
Peres was born in Poland in 1923 and began in politics as a close aide to Israel's founding father and first prime minister David Ben-Gurion. In a career spanning nearly seven decades, he has served in a dozen cabinets and twice as prime minister.
He shared the Nobel Peace Prize with Israel's late prime minister Yitzhak Rabin and Palestinian leader Yasser Arafat for a 1993 interim peace deal that they and their successors failed to turn into a durable treaty.
Unlike Peres, Rivlin, a former parliamentary speaker, is opposed to the creation of a Palestinian state.
A champion of Jewish settlements built on occupied land, Rivin, 74, has called for a confederation with the Palestinians rather than negotiating an independent state for them - something Palestinian leaders have long rejected.
Yet Rivlin, chosen by parliament last month, has won endorsements from Israeli doves for his longtime advocacy of Jewish-Arab cooperation and for a sense of humour known to cross political and ethnic lines.
Rivlin had tears in his eyes as he was sworn in as head of state, but he sounded a combative note against Gaza militants.
"They will not defeat us. Terror will not defeat us, or weaken our resolve or our spirit or conviction in our feeling of justice," the new president said. (Editing by Gareth Jones)