Hamas freed two dozen hostages held in Gaza and Israel released nearly 40 imprisoned Palestinians on Friday, completing the first exchange in a tense, temporary truce that halted the fighting after seven weeks of war.