A gunman opened fire outside an east Jerusalem synagogue Friday night, killing at least seven people and wounding four before police shot him, officials said.