WASHINGTON — President Barack Obama apologized to California Attorney General Kamala Harris “for the distraction created” when he remarked on her looks during a fundraiser on Thursday, his spokesman said.

Obama called Harris Thursday night after his comments generated criticism on social media and from political opponents, White House press secretary Jay Carney said.

“They are old friends and good friends, and he did not want in any way to diminish the attorney general’s professional accomplishments and her capabilities,” Carney said at a White House briefing.

On the last stop of a fundraising swing in California, Obama singled out Harris at the home of Levi Strauss heir John Goldman, praising her for her brilliance and dedication.

“She also happens to be by far the best-looking attorney general in the country,” the president said, prompting laughter from the crowd. “It’s true, come on.”

Obama also said that Harris “is a great friend and has just been a great supporter for many, many years.”

In his call to Harris, Obama “apologized for creating this distraction,” Carney said.

Obama, who was re-elected with a majority of support from female voters, has been criticized by some women’s groups after selecting men to lead the State, Treasury and Defense departments at the start of his second term. Those choices have been balanced more recently by the nominations of women for three cabinet-level positions.

Last month, he nominated Sylvia Mathews Burwell of the Wal-Mart Foundation as director of the Office of Management and Budget, and Gina McCarthy to lead the Environmental Protection Agency, where she’s been an assistant administrator.

In February, he announced his pick of Sally Jewell, chief executive officer at outdoor retailer REI, as the next Interior secretary.