LOS ANGELES — For most of his life, Blake Smith said, “every inch of my body craved male sexual contact.”

Mr. Smith, 58, who says he believes homosexual behavior is wrong on religious grounds, tried to tough it out. He spent 17 years in a doomed marriage while battling his urges all day, he said, and dreaming about them all night.

But in recent years, as he probed his childhood in counseling and at men’s weekend retreats with names like People Can Change and Journey Into Manhood, “my homosexual feelings have nearly vanished,” Mr. Smith said in an interview at the house in Bakersfield, Calif., he shares with his second wife, who married him eight years ago knowing his history. “In my 50s, for the first time, I can look at a woman and say ‘she’s really hot.’ ”

Mr. Smith is one of thousands of men across the country, often known as “ex-gay,” who believe they have changed their most basic sexual desires through some combination of therapy and prayer — something most scientists say has never been proved possible and is likely an illusion.