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 on 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, adding that the president “believes very strongly that Attorney General Harris is an excellent attorney general and that she’s done great work, and she’s dedicated and tough and brilliant.”

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 in January. 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 Recreation Equipment, as the next Interior secretary.

He also has appointed Julia Pierson to lead the Secret Service, the first woman to hold that job.

Harris, 48, worked on Obama’s re-election campaign and has been mentioned by Democratic Party officials as a possible nominee to the Supreme Court should a vacancy occur. She’s been attorney general of the most populous U.S. state since 2011. Before that, she was elected to two terms as the district attorney in San Francisco.

Harris is the first woman to hold the job in California and is among eight female attorneys general in the nation.

Obama’s opponent in the 2012 presidential election, Republican Mitt Romney, drew ridicule from Democrats last year when he said during a debate that his staff brought him “binders full of women” when he was looking to fill top state jobs as governor of Massachusetts.

Republicans suggested Thursday that Obama benefits from a double standard. A Twitter account of the Republican National Committee sent out the message: “Not awkward and perfectly fine for him to say, right?”