EU referendum: Welsh voters back Brexit
Leave has won the EU referendum campaign in Wales - and across the UK - with all Welsh council areas declared.
854,572 (52.5%) voters in Wales chose to leave the EU, compared with 772,347 (47.5%) supporting Remain.
Welsh Conservative leader and Leave supporter Andrew RT Davies said Welsh politics had changed forever but Labour's Lord Hain said there would be "tragic" consequences.
David Cameron announced he would step down as prime minister by October.
First Minister Carwyn Jones has said he fears jobs will be lost in Wales following the vote outcome and called for party and public unity in Wales.
In a statement in Downing Street he said he would attempt to "steady the ship" between now and then.
"We must now prepare for a negotiation with the European Union - this will need to involve the full engagement of the Scottish, Welsh and Northern Ireland governments to ensure that the interests of all parts of our United Kingdom are protected and advanced," Mr Cameron said.
The vast bulk of Wales' council areas, many of them Labour-supporting, voted for Leave with a majority in 17 backing Brexit.
Only five areas - Gwynedd, Cardiff, Ceredigion, the Vale of Glamorgan and Monmouthshire - voted for Remain.
Turnout was high at 71.7% for Wales.
Neil Hamilton, UKIP's assembly group leader, said: "I am absolutely delighted and I have to admit even a little surprised myself, as I hardly dared believe we could achieve this."
UKIP Wales leader Nathan Gill told BBC Radio's Good Morning Wales: "It is wonderful, we [all UK MEPs] will be given our P45s now.
"It is the 74 MEPs not the British people who are going to lose their jobs."
He said he was not surprised Wales voted to leave and said he had been predicting the outcome for a long time.
"Everywhere we have been for two to three years, our support has been galvanising," he said.
"People have been telling us they are fed up of the EU, saying it wasn't democratic, saying 'we want our freedom back' and that is what they are going to get."
Andrew RT Davies said: "It is clear that the fault lines of Welsh politics have now changed forever, and I am extremely proud to have been involved in this campaign."
He told Good Morning Wales that Wales will receive more investment outside the European Union.
He added: "I stood by my convictions [backing a leave vote] and stood by my beliefs. We have a great future ahead of us as we are a great trading nation."
As Leave campaigners celebrated their historic victory, leading figures from the Remain side lined up to warn of "very serious" and "dangerous" consequences from the decision.
Lord Hain said: "It is a tragic result for Wales which will have serious consequences for us."
Speaking to BBC Radio's Good Morning Wales, he said: "What leave voters will find is that they will be pleased in the short-term but in the long-term, the consequences are very serious. Those that voted leave are the ones that benefit most from EU funding."
He said the EU had become "the whipping boy", with "immigration becoming a toxic issue, even in areas where there has been no immigration".
With the potential for Scotland to call another independence referendum, he said: "We could have moved out of one union and lost another in the UK."
He said serious questions must be asked about whether the Welsh Government's planned M4 relief road and South Wales Metro project would now happen.
Simon Thomas, a Plaid Cymru AM whose party supported Remain, told BBC Wales he was extremely disappointed.
"I think its an absolute disaster from the point of view of building the Welsh economy over the next five to ten years," he said.
"This is very dangerous and disturbing territory that we're entering into."
His fellow Plaid AM Rhun ap Iorwerth called the Leave vote a "hammer blow to Wales economically" warning "the poorest will pay the price".
"We have woken up in a deep pit that we have dug ourselves with spades provided by a fear-driven campaign," he said.
Mark Williams, Welsh Liberal Democrat leader, said he was deeply disappointed, adding: "Now is not the time for more government infighting at the expense of the people of Wales."
Labour AM and ex-MEP Baroness Morgan said: "That crash in the market you hear is also the crashing of your pensions. This will impact on everyone."
Work and Pensions Secretary and former Welsh Secretary Stephen Crabb said he was "not surprised" by the results in Wales and voters had not trusted the messages from the Remain campaign.
He said voters said they were "sorry we don't believe what the Labour party and the government are saying about the benefits of the European Union".
First Minister Carwyn Jones is due to give a press conference at 09:15 BST.
Political commentator Daran Hill said: "Wales' decision to Leave comes down to a failure of Labour and the Labour-inclined Stronger In campaign to connect with, motivate and mobilise their voters.
"The Welsh voters have done what they haven't done since 1979 - they have rejected the establishment."
Live coverage of the results and reaction continues on BBC One Wales, on BBC Radio Wales and Radio Cymru.
Analysis from Vaughan Roderick, BBC Welsh Affairs editor
We have seen a very surprising pattern. We have seen working class Labour voters go fairly solidly "Vote Leave", far more strongly than we were expecting.
Leave won Bridgend - which is First Minister Carwyn Jones' territory - and they won Rhondda Cynon Taff, which is Leanne Wood's home territory.
So maybe it is not the individual politicians we should be looking at - it is actually a question of income and social class more than political affiliation or political leadership.
Are we looking at a situation where people who felt they have had nothing to lose voted to leave, whereas people who feel they have something to lose - Labour or Conservative - decided to vote remain?
It seems to me that there is an income and class distribution question far more than there is a political one.
David Cameron and George Osborne's big scare campaign did not work and there were issues over the timing of the referendum.
Because of the assembly election campaign, you only saw Carwyn Jones and Leanne Wood together three days before the vote took place.
That was far too late to turn their popularity into persuading people to vote to Remain.