This paper presents a novel mathematical programming model for the optimal power flow with transient stability constraints, considering a detailed fourth-order model for synchronous generators and their controls. Such controls are the simplified excitation system for voltage magnitude and a frequency control system formed by a governor and a turbine. Moreover, in order to manage convergence issues and to determine causes of instability, load shedding is included. The proposed model considers, in the same mathematical expression, the prefault or the initial steady stage, the fault stage, and the postfault. The differential equations that represent the rotor angle stability constraints were transformed into algebraic equations using the trapezoidal integration method. The proposed nonlinear programming model was implemented using the mathematical programming language AMPL and solved using the nonlinear solver IPOPT. The well-known WSCC 9-bus, and the IEEE 68-bus systems were used for testing accuracy and efficiency. A comparative analysis was also carried out with transient stability-constrained optimal power flow using the second-order generator model to be able to observe not only the economic differences but also to be able to compare the performance of the systems, that is, if the system configuration satisfies the requirements usually demanded by the transmission system operator. The results show the ability of the proposed model to predict the dynamic behavior of the system under contingency and to properly dispatch the generation resources to withstand these perturbations. It is concluded that a more detailed model provokes an overall improvement of the system stability, while performing economical and reliable dispatch decisions. • A new NLP mathematical programming model for the TSC-OPF problem. • The proposed model considers a detailed fourth-order model for generators. • The proposed model considers the excitation system, governor, and turbine controls. • A comparative analysis with the TSC-OPF using a second-order generator model.