HIV attacks CD4 cells of the immune system, leading to progressive immune deficiency. Antiretroviral therapy (ART) involves the use of HIV drugs to treat HIV infection and is administered daily to slow disease progression. This paper aims to develop and analyze a mathematical model of HIV transmission that incorporates pre-antiretroviral therapy counselling and HIV treatment to reduce the number of HIV-infected individuals with high-risk behaviours for HIV transmission. A nonlinear dynamical system is constructed, and model parameters are estimated from Indonesia’s annual HIV case data using a genetic algorithm method. The model exhibits two equilibrium points: the disease-free equilibrium and the endemic equilibrium. Stability analysis shows that disease-free equilibrium is globally asymptotically stable when the basic reproduction number is less than one. Optimal control theory is applied to a system that consists of two time-dependent controls, pre-antiretroviral therapy counselling and HIV treatment. Healthcare professionals provide pre-antiretroviral therapy counselling to help people with HIV understand the disease and the benefits of antiretroviral therapy. Pontryagin's maximum principle is employed to derive optimal control conditions. The optimal control problem is numerically solved using the forward–backward sweep method with a fourth-order Runge–Kutta scheme. Three potential strategies were developed and investigated in our simulation. Implementing the two combined controls could significantly reduce the number of HIV-infected individuals and improve overall disease control in the population.