An explosion on Friday near a gate to the campus of Kabul University in the Afghan capital killed six people and injured at least 27 as students waited to take an examination, officials said.