We conducted a randomized controlled trial of an individually-tailored, virtual perspective-taking intervention to reduce race and socioeconomic (SES) disparities in providers' pain treatment decisions. Physician residents and fellows (n=436) were recruited from across the United States for this two-part online study. Providers first completed a bias assessment task in which they made treatment decisions for virtual patients with chronic pain who varied by race (Black/White) and SES (low/high). Providers who demonstrated a treatment bias were randomized to the intervention or control group. The intervention consisted of personalized feedback about their bias, real-time dynamic interactions with virtual patients, and videos depicting how pain impacts the patients' lives. Treatment bias was re-assessed one week later. Compared to the control group, providers who received the tailored intervention had 85% lower odds of demonstrating a treatment bias against Black patients and 76% lower odds of demonstrating a treatment bias against low SES patients at follow-up. Providers who received the intervention for racial bias also showed increased compassion for patients compared to providers in the control condition. Group differences did not emerge for provider comfort in treating patients. Results suggest an online intervention that is tailored to providers according to their individual treatment biases, delivers feedback about these biases, and provides opportunities for increased contact with Black and low SES patients, can produce substantial changes in providers' treatment decisions, resulting in more equitable pain care. Future studies should examine how these effects translate to real-world patient care, and the optimal timing/dose of the intervention.