A 10-day demonstration of Israeli slum dwellers, which had become a major source of embarrassment for Prime Minister Menachem Begin's government, ended peacefully today when the squatters packed up their belongings and voluntarily evacuated the tent city they had built on public land.

There were some tense moments when about 1,000 well-armed and helmeted policemen who had been massed for the past two days converged on the camp, ready to move the 38 families there by force if necessary.

The clash was averted as a result of the last-minute intervention of Mayor Teddy Kollek. He promised the squatters who had pitched their tents in an open field on the southern outskirts of Jerusalem that he would recommend the establishment of a cooperative village on their behalf.

Earlier today the would-be settlers lost a court battle when the Israeli Supreme Court, which yesterday issued a temporary injunction on their behalf, refused subsequently to issue an order of restraint against the police. The court ordered them to evacuate the area immediately, but Yamin Suissa, one of their leaders, at first said that they would not obey the court order. Toward dusk, however, the squatters struck their tents.