WASHINGTON — President Barack Obama late Thursday night called Kamala Harris, the California attorney general, and apologized to her for saying that she was the “best-looking attorney general in the country.”

Obama made the comment Thursday morning at a fundraiser outside San Francisco. He praised Harris as being “brilliant,” adding, “she is dedicated and she is tough” before commenting on her looks. “She also happens to be by far the best-looking attorney general in the country,” the president told the wealthy donors, who responded with surprise and applause.

There was a quick reaction on social media sites, with some people accusing Obama of being sexist and others defending his comment as harmless.

The president’s aides apparently knew the potential for political damage. Soon after Air Force One returned Obama from his West Coast fundraising trip, he called Harris and apologized, according to Jay Carney, the White House press secretary.

“You know, they are old friends and good friends,” Carney said, “and he did not want in any way to diminish the attorney general’s professional accomplishments and her capabilities.”

Carney repeatedly remarked on Harris’ abilities, calling her “a remarkably effective leader as attorney general” and “an excellent attorney general” who has “done great work.”

The president, Carney said, “fully recognizes the challenge women continue to face in the workplace and that they should not be judged based on appearance.”

A spokesman for Harris, Gil Duran, said in a statement Friday: “The attorney general and the president have been friends for many years. They had a great conversation yesterday, and she strongly supports him.”

While Harris did not seem offended, others were on her behalf. Robin Abcarian wrote on the website of The Los Angeles Times that the comment was “more wolfish than sexist,” and “may be a little problem he needs to work on.”

Joan Walsh wrote on Salon that “my stomach turned over” when she heard about the comment. “Those of us who’ve fought to make sure that women are seen as more than ornamental — and that includes the president — should know better than to rely on flattering the looks of someone as formidable as Harris,” she said.