In this paper, a class of anisotropic compact stars is analyzed in Heintzmann geometry. The Einstein field equations (EFEs) have been solved to obtain the stellar model in presence of pressure anisotropy. We have considered the [Formula: see text] metric component as proposed by Heintzmann, and by solving the EFEs, the [Formula: see text] metric component is evaluated in the presence of pressure anisotropy. It is noted that for an isotropic star ([Formula: see text]), the maximum mass lies within the range 1.87–3.04[Formula: see text] for radii ranging between 8–13[Formula: see text]km. For anisotropic compact stars, the maximum mass increases with [Formula: see text] and lies within the range 1.99–3.23 [Formula: see text] for anisotropy parameter [Formula: see text]. The physical viability of the model is examined by applying our model to study the properties of a few known compact objects. All the stability conditions are fulfilled in the proposed model. It is also interesting to note that the maximum mass calculated from our model from geometrical consideration and solving the TOV equation is approximately equal, and the radii predicted from the present model comply with the estimated radius from observations of recently observed pulsars and lighter compact objects of GW events such as GW 190814 and GW 170817.