PURPOSE To characterize racial and ethnic disparities and trends in opioid access and urine drug screening (UDS) among patients dying of cancer, and to explore potential mechanisms. METHODS Among 318,549 non-Hispanic White (White), Black, and Hispanic Medicare decedents older than 65 years with poor-prognosis cancers, we examined 2007-2019 trends in opioid prescription fills and potency (morphine milligram equivalents [MMEs] per day [MMEDs]) near the end of life (EOL), defined as 30 days before death or hospice enrollment. We estimated the effects of race and ethnicity on opioid access, controlling for demographic and clinical factors. Models were further adjusted for socioeconomic factors including dual-eligibility status, community-level deprivation, and rurality. We similarly explored disparities in UDS. RESULTS Between 2007 and 2019, White, Black, and Hispanic decedents experienced steady declines in EOL opioid access and rapid expansion of UDS. Compared with White patients, Black and Hispanic patients were less likely to receive any opioid (Black, –4.3 percentage points, 95% CI, –4.8 to –3.6; Hispanic, –3.6 percentage points, 95% CI, –4.4 to –2.9) and long-acting opioids (Black, –3.1 percentage points, 95% CI, –3.6 to –2.8; Hispanic, –2.2 percentage points, 95% CI, –2.7 to –1.7). They also received lower daily doses (Black, –10.5 MMED, 95% CI, –12.8 to –8.2; Hispanic, –9.1 MMED, 95% CI, –12.1 to –6.1) and lower total doses (Black, –210 MMEs, 95% CI, –293 to –207; Hispanic, –179 MMEs, 95% CI, –217 to –142); Black patients were also more likely to undergo UDS (0.5 percentage points; 95% CI, 0.3 to 0.8). Disparities in EOL opioid access and UDS disproportionately affected Black men. Adjustment for socioeconomic factors did not attenuate the EOL opioid access disparities. CONCLUSION There are substantial and persistent racial and ethnic inequities in opioid access among older patients dying of cancer, which are not mediated by socioeconomic variables.