Hamas agrees to withdraw militia