Israel said its soldiers had come under fire from militants inside the school.
Earlier, the International Committee of the Red Cross (ICRC) warned of a "full-blown humanitarian crisis" in Gaza. Speaking on the 11th day of the Israeli assault, a senior ICRC official, Pierre Kraehenbuhl, said life in Gaza had become intolerable.
GAZA CRISIS BACKGROUND
Palestinian medical sources say more than 600 people have been killed since the attacks began, and Mr Kraehenbuhl said much more needed to be done to protect civilians. At least 70 Palestinians and five Israeli soldiers were killed on Tuesday.
One soldier was killed in an exchange of fire with militants in Gaza City, while four others were killed by shellfire from their own tanks earlier in the day, Israeli military officials said.
Israel says its offensive is stopping militants firing rockets, but at least five hit southern Israel on Tuesday, with one reaching the town of Gedera, about 40km (25 miles) from Gaza, and injuring a baby.
Three Israeli civilians and one soldier have been killed by rocket fire from the Gaza Strip since the offensive began 10 days ago. The UN aid agency in Gaza, Unrwa, said three artillery shells had landed close to the al-Fakhura school on Tuesday afternoon, spraying shrapnel on people both inside and outside the building.
About 350 people had sought refuge at the school in effort to escape the fighting between Israeli soldiers and militants on the outskirts of the refugee camp, to the east of Gaza City.
Television footage showed bodies scattered on the ground amid pools of blood.
Palestinian doctors at nearby hospitals had earlier said that at least 40 people had been killed. The Kamal Adwan hospital in Beit Lahiya said 30 people had died there. A further 10 people died at the al-Shifa hospital in Gaza City, doctors said.
The UN officials said they regularly provided the Israeli military with exact co-ordinates of their facilities, and that the school was in a built-up area. The Israeli military said that, according to initial checks, its soldiers had come under mortar fire from militants inside the school.
"The force responded with mortars at the source of fire," it said in a statement. "Hamas cynically uses civilians as human shields."
It later reported that two Hamas militants had been among those killed at the school. It identified the two men as Imad and Hassan Abu Askar, saying they were members of a rocket-launching cell.
Earlier in the day, at least three Palestinians were killed when another school was hit in the Shati camp, UN officials said. Ten people were also injured at a UN health centre in the Bureij refugee camp.
Maxwell Gaylard, the UN humanitarian co-ordinator for the Palestinian territories, described the incidents as tragic and demanded an independent investigation.
The director of operations for Unrwa, John Ging, meanwhile told the BBC that the conditions in Gaza were "horrific". The BBC's Rushdi Abu Alouf reports from a UN school inside a Gaza refugee camp.
"Nowhere is safe for civilians here in Gaza at the moment. They are fleeing their homes and they are right to do it when you look at the casualty numbers," he said.
"It's very, very dangerous, and even the 14,000 who have sought refuge in our schools and shelters, they are not safe either." Mr Ging said international leaders had a responsibility to act to protect civilians.
"You cannot conduct huge military operations in such densely-populated places without killing hundreds and injuring thousands of civilians," he added. Meanwhile, Israeli forces have pushed further south on the Gaza Strip and clashed with militants near Gaza City.
Skirmishes were also reported on the edges of the Deir al-Balah and Bureij refugee camps in central Gaza, and witnesses said Israeli tanks and infantry were advancing on Khan Younis. Information about what is happening inside Gaza is limited as Israel has barred foreign reporters from entering.
'Time against us'. Diplomatic efforts to try to end the violence are gathering pace.
French President Nicolas Sarkozy said he had asked his Syrian counterpart, Bashar Assad, to help convince Hamas to co-operate with efforts to end the Israeli offensive. Syria is regarded as a main backer of Hamas.
"The loss of civilian life in Gaza and Israel is a source of deep concern for me", said the US President-elect Barack Obama
When later asked about the deaths at UN school in Gaza, Mr Sarkozy said: "It reinforces my determination for all this to stop as quickly as possible. Time is working against us. We must find a solution." US State Department spokesman Sean McCormack said the US would like to see "an immediate ceasefire" in Gaza.
"An immediate ceasefire that is durable, sustainable and not time-limited," he told reporters in Washington, according to the Reuters news agency. "We want, obviously, to be constructive," he added.
US President-elect Barack Obama meanwhile broke his silence about the conflict, telling reporters that "the loss of civilian life in Gaza and Israel is a source of deep concern for me".
However, he also reiterated that he would adhere to his principle that only President George W Bush would speak for US foreign policy at this time. US Secretary of State Condoleezza Rice is to hold talks in New York with Palestinian Authority President Mahmoud Abbas, who is going to the UN with several Arab foreign ministers to lobby for a ceasefire. The BBC's Laura Trevelyan in New York says the contours of an agreement are taking shape - international monitors along the Egypt-Gaza border to stop Hamas smuggling weapons and firing rockets at Israel, and the creation of a humanitarian corridor in southern Gaza to ensure that aid goes to the Palestinians.The question now is whether Hamas will accept such a deal and if a call for a ceasefire will be heeded by Israel, our correspondent says.
Hamas has said that Israeli attacks on Gaza must stop and the crossings into the territory, which Israel controls, must be fully opened, before it agrees to a ceasefire. Israeli Prime Miniser Ehud Olmert said on Tuesday that the military campaign in Gaza would continue until Israel had completely wiped out Hamas's ability to fire rockets into Israel.