Heating, ventilation, and air conditioning (HVAC) systems play a crucial role in either increasing or decreasing the risk of airborne disease transmission. High ventilation, for instance, is a common method used to control and reduce the infection risk of airborne diseases such as COVID-19. On the other hand, high ventilation will increase energy consumption and cost. This paper proposes an optimal HVAC controller to assess the trade-off between energy consumption and indoor infection risk of COVID-19. To achieve this goal, a nonlinear model predictive controller (NMPC) is designed to control the HVAC systems of a university building to minimize the risk of COVID-19 transmission while reducing building energy consumption. The NMPC controller uses dynamic models to predict future outputs while meeting system constraints. To this end, a set of dynamic physics-based models are created to capture heat transfer and conservation of mass, which are used in the NMPC controller. Then, the developed models are experimentally validated by conducting experiments in the ETLC building at the University of Alberta, Canada. A classroom in the building is equipped with a number of sensors to measure indoor and outdoor environmental parameters such as temperature, relative humidity, and CO2 concentration. The validation results show that the model can predict room temperature and CO2 concentration by 0.8%, and 2.4% mean absolute average errors, respectively. Based on the validated models, the NMPC controller is designed to calculate the optimal airflow and supply air temperature for every 15 min. The results for real case studies show that the NMPC controller can reduce the infection risk of COVID-19 transmission below 1% while reducing energy consumption by 55% when compared to the existing building controller.