After three weeks of carnage in Gaza, there were tentative signs of a ceasefire last night. But the bitter legacy of the past 22 days for Israel is that, while it declares victory on the battlefield, the country's reputation has rarely sunk so low.

Yesterday the United Nations called for a war crimes investigation after two children, aged five and seven, were killed when, it claimed, an Israeli tank shell hit a school sheltering some of the more than 40,000 internally displaced refugees.

"These two little boys are as innocent, indisputably, as they are dead," said John Ging, head of the UN Relief and Works Agency (UNRWA) in Gaza. In Jerusalem, Chris Gunness, the organisation's spokesman, added: "There has to be an investigation to determine whether a war crime has been committed."

Download the new Independent Premium app Sharing the full story, not just the headlines

Mr Gunness used unusually strong language. But the call came at the culmination not only of a rising civilian death toll but also a series of attacks on UN installations and, in some cases, the people who were under the UN's care at the time. The most lethal of these was an earlier shelling in which 43 internally displaced Gazans, sheltering in the Fakhura UNRWA school in Jabalya, were killed on 6 January.

Yet last week, an attack was launched that was – or should have been – as diplomatically embarrassing. For while the UN Secretary-General Ban Ki-moon was in the region for talks with Israeli ministers, an attack was launched on the main UNRWA compound, injuring three, setting fire to fuel and food in the depot with what Mr Ging said was white phosphorus, and sending up a dense plume of black smoke which became the defining image of the day's television coverage.

While Mr Ban said that the defence minister, Ehud Barak, had apologised for a "grave error", government spokesmen immediately suggested – just as they had initially in the Jabalya case, although UNRWA officials say this was later retracted in private conversations – that there had been firing by militants from in or around the UN compound. Mr Ging described the claim as "nonsense", adding that the UN had warned the Israelis that the compound was in danger from shelling, and had provided them with GPS co-ordinates to prevent an attack.

It began to seem like a pattern: after each episode of "collateral damage", international organisations would accuse the Israeli military of targeting buildings and civilian areas; then the Israelis would respond that they had simply returned fire after Hamas fighters had used these places to launch attacks. There was no discussion of whether the Israeli military's use of force was proportionate or not.

But while international concern grew over the rising daily toll of deaths in Gaza, the Israeli government continued to receive consistent majority support domestically. A common view expressed by many Israelis was that Hamas had brought it all upon itself by continuing to fire rockets into southern Israel for the past eight years.

By last night, it was beginning to look as if the Israeli mood was changing. With an election looming and, even more decisively perhaps, a new US president ready to take office on Tuesday, foreign minister Tzipi Livni and Mr Barak were both – however belatedly – ready to call a halt at the beginning of last week. Only the Prime Minister Ehud Olmert, apparently eager to exorcise the failures of Lebanon in 2006, appeared to be pursuing the war with enthusiasm. Few Israelis have yet publicly recalled the prescient remark of one of the fathers of modern Zionism, Chaim Weizmann: "The world will judge the Jewish state by the way it will treat the Arabs."

For many Israelis the cost of the war became clear when a Hebrew-speaking physician, Izz el-Deen Aboul Aish, who had been frequently interviewed on prime-time TV by a top reporter, Shlomi Eldar, phoned the journalist live on air to announce that his three daughters had been killed. "My God, my girls, Shlomi," viewers heard him say. "Can't anybody get to us, please?" As Mr Eldar got the authorities to allow rescue services to the stricken family, it was not lost on commentators that the same disaster was striking hundreds of other families without direct access to Israeli TV.

Ari Shavit, a leading columnist on the newspaper, 'Haaretz', was a fervent proponent of the "just war" at the outset. By Friday, he was writing: "Shelling a United Nations facility is something not to be done at any time, but doing it on the day when the UN Secretary-General is visiting Jerusalem is beyond lunacy. The level of pressure the Israel Defence Forces have been exerting on Gaza may be squeezing Hamas, but it is destroying Israel. Destroying its soul and its image. Destroying it on world television screens, destroying it in the living rooms of the international community... "