SummaryThis paper deals with an optimal control problem of a time‐delayed differential equation model that describes the interactions between hepatitis B virus (HBV) with HBV DNA‐containing capsids, liver cells (hepatocytes), and cytotoxic T‐lymphocyte immune response. Both the treatment and the intracellular delay are incorporated into the model. Furthermore, the existence of the optimal control pair is studied, and Pontryagin's minimum principle is used to characterize these 2 optimal controls. The first of them represents the efficiency of drug treatment in preventing new infections, whereas the second stands for the efficiency of drug treatment in inhibiting viral production. The optimality system is derived and solved numerically using the forward and backward difference approximation. Finally, numerical simulations are established to show the role of optimal therapy in controlling viral replication.