This study aimed to estimate the medical cost of cancer in the first five years of diagnosis and in the final six months before death in people who developed cancer after human immunodeficiency virus (HIV) infection in Korea. The study utilized the Korea National Health Insurance Service-National Health Information Database (NHIS-NHID). Among 16,671 patients diagnosed with HIV infection from 2004 to 2020 in Korea, we identified 757 patients newly diagnosed with cancer after HIV diagnosis. The medical costs for 60 months after diagnosis and the last six months before death were calculated from 2006 to 2020. The mean annual medical cost due to cancer in HIV-infected people with cancer was higher for acquired immunodeficiency syndrome (AIDS)-defining cancers (48,242 USD) than for non-AIDS-defining cancers (24,338 USD), particularly non-Hodgkin’s lymphoma (53,007 USD), for the first year of cancer diagnosis. Approximately 25% of the cost for the first year was disbursed during the first month of cancer diagnosis. From the second year, the mean annual medical cost due to cancer was significantly reduced. The total medical cost was higher for non-AIDS-defining cancers, reflecting their higher incidence rates despite lower mean medical costs. The mean monthly total medical cost per HIV-infected person who died after cancer diagnosis increased closer to the time of death. The estimated burden of medical costs in patients with HIV in the present study may be an important index for defining healthcare policies in HIV patients in whom the cancer-related burden is expected to increase.