We study the elastic properties, electronic structure and equation of state of titanium diboride and magnesium diboride using a first-principles pseudopotential method. We show that the results of the calculations carried out using the gradient-corrected approximation of the density-functional theory are in excellent agreement with the most recent experimental data. These results confirm that early reports of anomalously high elastic anisotropy of TiB2 were based on erroneous experimental data for the off-diagonal components of the elastic coefficients tensor. Present results for TiB2 are more accurate than previously reported Hartree-Fock calculations. Predicted elastic properties of the recently discovered superconductor, MgB2, are presented and compared to contradictory experimental estimates of bulk and linear compressibilities.