The Press–Schechter, excursion set approach allows one to make predictions about the shape and evolution of the mass function of bound objects. The approach combines the assumption that objects collapse spherically with the assumption that the initial density fluctuations were Gaussian and small. The predicted mass function is reasonably accurate, although it has fewer high-mass and more low-mass objects than are seen in simulations of hierarchical clustering. We show that the discrepancy between theory and simulation can be reduced substantially if bound structures are assumed to form from an ellipsoidal, rather than a spherical, collapse. In the original, standard, spherical model, a region collapses if the initial density within it exceeds a threshold value, δsc. This value is independent of the initial size of the region, and since the mass of the collapsed object is related to its initial size, this means that δsc is independent of final mass. In the ellipsoidal model, the collapse of a region depends on the surrounding shear field, as well as on its initial overdensity. In Gaussian random fields, the distribution of these quantities depends on the size of the region considered. Since the mass of a region is related to its initial size, there is a relation between the density threshold value required for collapse and the mass of the final object. We provide a fitting function to this δec(m) relation which simplifies the inclusion of ellipsoidal dynamics in the excursion set approach. We discuss the relation between the excursion set predictions and the halo distribution in high-resolution N-body simulations, and use our new formulation of the approach to show that our simple parametrization of the ellipsoidal collapse model represents an improvement on the spherical model on an object-by-object basis. Finally, we show that the associated statistical predictions, the mass function and the large-scale halo-to-mass bias relation, are also more accurate than the standard predictions.