Witnesses said armed men on Monday stopped a UN vehicle driving through the town and kidnapped the two UN workers and their driver.
The United Nations confirmed the three were missing.
Later on Monday, Palestinian security officers broke into a building in the town of Khan Yunus where the three were being held and freed them, sparking a gun battle between the police and the kidnappers.
The three, a Briton, a Swede and a Palestinian, who worked for the UN agency for Palestinian refugees (UNRWA), were taken to safety by police, security officials and witnesses said.
“The UN workers were freed but the kidnappers managed to flee and they are currently being pursued,” a security source said.
Lawlessness and internal Palestinian violence has grown in Gaza in recent months as armed groups seek to show their power and clash with security forces trying to consolidate authority in the government.