A controversial UKIP member of the Welsh Assembly has won a three-way battle to lead the party in the Senedd.
Gareth Bennett has blamed immigrants for rubbish in Cardiff, and claimed transgender people undermined society by their "deviation from the norm".
He becomes the fourth leader of UKIP in Wales since the 2016 assembly election.
Runner-up Neil Hamilton said he could "happily" work with Mr Bennett, but outgoing leader Caroline Jones said she had "a lot of thinking to do".
UKIP leader Gerard Batten said he now expected his Welsh Assembly members to "work together for UKIP's cause and get on with the job."
The party ordered the ballot of nearly 900 members in Wales to settle a row sparked when Ms Jones ousted former Tory MP Mr Hamilton as group leader in May.
Mr Bennett, AM for South Wales Central, beat Mr Hamilton by 269 to 193 votes in the second round of counting.
Ms Jones - leader for just six weeks - was eliminated after the first round with 130 votes.
The result was announced by party chairman Tony McIntyre at UKIP headquarters in Newton Abbot, Devon, shortly after the votes were counted there on Friday.
Mr Batten said: "I wish to extend my congratulations to Gareth Bennett.
"I now expect all elected members in Wales to work together for UKIP's cause and to get on with the job."
Mr Bennett said he was "delighted" to have won the support of the party members in Wales "to take UKIP forward into the next assembly term".
He told BBC Wales he thought his anti-devolution stance was a "major factor" in his victory.
The AM has called for a referendum on whether the assembly should be abolished, and has criticised spending on the Welsh language.
"I don't think party members in Wales have endorsed me because of my brilliant personality, because I have the most charisma or anything like that," he said.
"It's just purely and simply because I had the policies."
Mr Bennett said he was confident he could unify the group, adding that it was his idea to call for a membership ballot to settle the matter of the leadership.
Defeated candidate Caroline Jones congratulated Mr Bennett on his victory, although she said the party's decision to hold an election just weeks after she became leader "doesn't leave a good taste in my mouth".
She said she bore no "malice" to him but added: "I am concerned about my future now. I've got a lot of thinking to do.
"I don't know where a woman's place is in my party.
"I don't know what my future holds."
Neil Hamilton "warmly congratulated" Mr Bennett, saying on Twitter: "He is a good friend of mine and I can work happily with him.
"For many UKIP members, the election was a referendum on the Assembly's very existence. Clearly, we must all learn from this."
There is a temptation to laugh at this but it really isn’t funny. A deeply offensive man but not amusing in the slightest. He is however the clear choice of @UKIPWales members. That tells you all you need to know. https://t.co/KWT4bbPI9l— Vaughan Gething AM (@vaughangething) August 10, 2018
Reaction from other parties was more scathing.
For Welsh Labour, Health Secretary Vaughan Gething described Mr Bennett as a "deeply offensive man but not amusing in the slightest", while fellow Labour AM Lee Waters said: "Game over for UKIP in the Assembly? I can't see several of their AMs staying [in] the group with Gareth Bennett as their leader."
Plaid Cymru leader Leanne Wood said she had been "consistent in my criticism of UKIP as a party that cannot and will not represent the values of Wales", adding that she thought their demise would be "welcomed".
In response, Mr Bennett told BBC Radio Wales' Good Evening Wales programme: "I'm not somebody who's going to go along with political correctness.
"I'm not going to be closed down by people like Leanne Wood and Vaughan Gething."
With 876 UKIP members in Wales eligible to vote, 514 did so, resulting in a turnout of 58.7%.
Gareth Bennett becomes UKIP's fourth leader in Wales since Nathan Gill - appointed by Nigel Farage - led the 2016 assembly election campaign which saw UKIP win its first seven Senedd seats.
The group, which has been rocked by rows, has since shrunk to just five AMs, with the departure of Mr Gill - who sat as an independent before quitting the assembly - and of Mark Reckless, who now sits with the Conservatives.
Analysis by David Deans, BBC Wales political reporter
There are now more UKIP AMs who have been leaders than haven't. Two have had a go - and now we have the third.
Mr Bennett will now have to unify his group - who under Caroline Jones were struggling to even hold meetings - but that could be a tall order.
On Friday, Caroline Jones was unclear about whether she would stick by the team of five.
She is clearly upset about how the whole election came about, and the new leader and former leader have clashed in the past.
But if he holds it together Mr Bennett's victory - given his anti-devolution stance - could effectively turn UKIP into the anti-assembly party at the next Senedd elections in 2021.