Using computer simulations, we identify the mechanisms causing aggregation and structural arrest of colloidal suspensions interacting with a short-ranged attraction at moderate and high densities. Two different nonergodicity transitions are observed. As the density is increased, a glass transition takes place, driven by excluded volume effects. In contrast, at moderate densities, gelation is approached as the strength of the attraction increases. At high density and interaction strength, both transitions merge, and a logarithmic decay in the correlation function is observed. All of these features are correctly predicted by mode coupling theory.