Cain, from Bronxville High School in New York, topped the record of 2:02.04 set by Amy Weissenbach of Harvard-Westlake High in 2011.
She also is the first American junior athlete to run the 800 under 2 minutes, breaking Kim Gallagher's mark junior of 2:00.07 in 1982.
"Down that backstretch I think I was the most determined person out there," said Cain, who battled fellow American Alysia Montano to the finish. "I said to myself, 'I'm going to break that two-minute barrier.'"
Francine Niyonsaba of Burundi won the 800 in 1:56.72, a meet record and a world best this season. But the sellout crowd of 12,816 erupted into cheers when Cain's record was announced. One fan shouted to the high school junior: "Come to Oregon!"
"I'm not really used to this. I'm still a star-struck little kid out there, so it's really cool," Cain said.
Gatlin won the Olympic gold medal at the Athens Games but his promising career was derailed in 2006 by a positive drug test that led to a four-year ban.
He has since worked hard to repair his past and was the defending champion at the Prefontaine, winning last year in 9.9 in a tuneup for the U.S. Olympic trials.
"I felt like I had a pretty good start, and I brought it home pretty good," Gatlin said. "Last year, my 20 meters before the finished line wasn't as strong as I wanted it to be. That's what we've been working on."
Gatlin took longer than any other athlete on his victory lap, stopping frequently to sign autographs and pose for pictures.
1, Justin Gatlin, U.S., 9.88. 2, Michael Rodgers, U.S., 9.94. 3, Ryan Bailey, U.S., 10.00. 4, Nesta Carter, Jamaica, 10.03. 5, Derrick Atkins, Bahamas, 10.08. 6, Keston Bledman, Trinidad and Tobago, 10.10. 7, Richard Thompson, Trinidad and Tobago, 10.21. 8, Kemar Bailey Cole, Jamaica, 10.24.