Kim took a six-shot lead into the final round but a course record-equalling 64 from England's Jodi Ewart Shadoff took her to within two shots of the lead.
But Kim, 29, maintained her form to post a 71 and win by two shots.
Another Englishwoman, Georgia Hall, had to settle for a tie for third after a 70, alongside American Michelle Wie (66) and German Caroline Masson (67).
A superb run of scoring saw Ewart Shadoff follow a birdie on the second hole with five in a row from the sixth and another on the 13th.
The 29-year-old from Northallerton then birdied the 17th to close the gap to two and parred the last to complete a 64, equalling the record set on day one by Wie and matched by Inbee Park in round three.
However, Kim, who famously missed a one-foot putt to win the Kraft Nabisco Championship - now called the ANA Inspiration - in 2012, was able to par the final five holes for a winning total of 18 under par.
Ewart Shadoff's runners-up finish is her best result in a major and secured her place on Europe's Solheim Cup team to take on the United States in Iowa from 18-20 August.
Wie closed with a six-under 66 to post her best major finish since winning her sole major title at the 2014 US Open.
Sally Watson, the only Scot left in the tournament, had a disappointing 76 to finish four over par in her last tournament before retiring.
South Korea's Kim In-kyung held her nerve to claim a first major title by winning the Women's British Open.