The mayor of San Diego, Jerry Sanders, testified yesterday before a federal trial on gay marriage how he came to change his mind on the issue.

Sanders, a Republican, was opposed to gay marriage but changed his mind after his daughter Lisa revealed she was a lesbian.

He appeared before a trial in California which is examining whether Proposition 8, which banned gay marriage in the state, was constitutional.

With his wife and daughter in the room, he told the court he had been a strong supporter of civil unions but had been against gay marriage until 2007. His daughter worked on his election campaign in 2005 but he said she had never tried to persuade him to support same-sex marriage.

But he changed his mind when he planned to veto a city council friend-of-the-court resolution supporting a lawsuit which called for same-sex marriage.

Sanders told the court he was shocked at the “depth of hurt” he saw at a meeting of gays and lesbians over the issue and the next day, he called a press conference where he tearfully announced he had changed his view.

He said: “I was absolutely shocked at the depth of the hurt, the depth of the feeling. . . What hit me was that I had been prejudiced.”

Sanders was cross-examined by an attorney for the opposing side. He said that opposition to gay marriage in favour of civil unions did not make people “bigots”, but added: “I believe they were saying an entire class of people doesn’t deserve the same treatment in their relationships.”

Lee Badgett, an economist at the University of Massachusetts, also testified yesterday. She said that gay unions had been taking place for so long that allowing gay couples to marry would not damage traditional marriage.

Lawyers for gay marriage supporters are expected to finish presenting their case this week. Another of those set to appear before the court will be Ryan Kendall, a gay man who forced to under-go ‘ex-gay’ therapy in an attempt to turn him straight.