Labour has fallen short of a majority in the Welsh Assembly as UKIP won its first seats in the Senedd.
Former Tory MPs Neil Hamilton and Mark Reckless were among seven UKIP AMs elected via the regional lists.
Labour remains the largest party with 29 of the 60 seats in Cardiff Bay, and suffered the shock loss of Leighton Andrews to Plaid Cymru leader Leanne Wood in Rhondda.
Plaid won 12 seats, the Conservatives 11, and the Liberal Democrats one.
Kirsty Williams increased the Lib Dem’s majority in Brecon and Radnorshire but announced she was stepping down as party leader, saying she had to “take responsibility” for the Lib Dem losses.
It is understood the new assembly could meet for the first time next week.
Labour’s UK leader Jeremy Corbyn said he wanted to “congratulate the Labour Party in Wales for its excellent results”.
First Minister Carwyn Jones said Labour was seeking the views of opposition parties, although senior party sources played down the idea of any formal coalition talks.
Mr Jones said he wanted to avoid “many weeks of uncertainty” and that the public would be looking to Labour to form an administration.
He told reporters on Friday he was talking to the sole remaining Lib Dem AM Ms Williams, and was also seeking Plaid Cymru’s views.
“We have to wait and see what the views of other parties might be,” he said.
“I’ve made it clear we can’t work with the Tories or UKIP in terms of a coalition – of course not, they’re far too far to the right of us.
“[We are] talking obviously to Kirsty Williams, seeing what the views of Plaid Cymru are – we don’t know, there are different views within Plaid Cymru.
“And so there are very early days yet, but people will look to us to form a government, as by far the largest party.
“We have to do that fairly quickly,” Mr Jones added.
“We’ve got a steel crisis that has to be dealt with and the last thing that Wales needs is a period of uncertainty for many weeks.”
A senior Labour MP said the party did not need to do a deal with Plaid Cymru, a party Labour shared power with between 2007 and 2011.
Shadow Work and Pensions Secretary Owen Smith told the BBC the decision was “a question for Carwyn and his ministers in the assembly”.
“I’m not going to tell them what they should do, but I think they’ve probably got enough to govern on their own, if they wish,” said the Pontypridd MP.
“I certainly don’t think they need to forge any sort of alliance with Plaid Cymru.”
Plaid leader Leanne Wood said she could not see how her party could be in the business of “propping up” Labour “in any way”.
“But I want to take time to reflect, to speak to my colleagues and we will shortly decide the strategy for the next period in Plaid Cymru’s development,” she added.
Welsh Secretary Alun Cairns congratulated Mr Jones on his election success, saying he wanted to work with the new Welsh Government to deliver “economic security” for people in Wales.
He called on all parties to “put aside political differences and get on with the big job of delivering projects that will really benefit people’s lives”.
Reacting to UKIP’s first ever assembly seats, party leader Nigel Farage said: “It is a victory not just for the party or myself but especially one for our leader in Wales, Nathan Gill.
“He is an honest, decent, hard working man and I have found him to be a loyal ally at all times.
“I want him to lead our now large voice in Wales to campaign for Brexit”, he added, referring to the referendum on UK membership of the European Union on 23 June.
Mr Hamilton, who lost his seat as a Conservative MP in the 1997 general election, predicted assembly politics would never be the same again with UKIP at the Senedd.
“This has been quite a surprising turn of events for me,” he said.
“I hadn’t anticipated at the age of 67 that I would once again be elected to public office, particularly after I had been liberated from it so spectacularly in 1997 by the electorate.”
Later, when asked about Mr Farage’s reported unhappiness at his selection as a candidate, Mr Hamilton told the BBC: “We will all work together as a team, regardless of things that have divided us hitherto.”
The shock result of the election was when Ms Wood ousted Labour’s Public Services Minister Leighton Andrews in Rhondda.
She said her victory, which was a 24% swing from Labour to Plaid, was a “new dawn” for Rhondda after claiming 11,891 votes – nearly 3,500 more than Mr Andrews.
“To win here, in the Rhondda, to win where you’ve lived all your life and grown up is a real honour,” she added.
It was the only constituency seat to change hands in the election.
Finance Minister Jane Hutt had a close result in Vale of Glamorgan, where her majority over the Tories was cut from nearly 4,000 to 777.
Huw Irranca-Davies, who quit as a Labour MP to stand in the assembly election, retained Ogmore for the party.
It was a disappointing night for the Conservatives, who failed to win any of their target seats and fell into third place behind Plaid Cymru.
While the Tories took Gower and Vale of Clwyd from Labour at the 2015 general election, the party failed to capitalise on either in the assembly poll.
They also failed to capture Labour-held Cardiff North or Vale of Glamorgan, and fell from 14 to 11 seats in total.
Welsh Conservative leader Andrew RT Davies said he was “proud that we have fought a positive and engaging campaign”, and claimed the party had some “strong results” with “clear momentum in seats we have never won at an assembly level”.
But an ex-Conservative AM called the party’s performance “poor” and said Mr Davies should now “consider” whether he should stay as leader.
Former Welsh Conservative health and education spokesman Jonathan Morgan said: “The results were a mixed bag but it’s disappointing to go backwards in Cardiff North and overall it’s a poor performance.”
Monmouth AM Nick Ramsay said the party’s problems could not be “brushed under the table” and the leadership needed to be discussed, but he backed Mr Davies after a “difficult” campaign.
The Conservative assembly group will meet on Monday to discuss strategy.
Plaid Cymru’s total went up from 11 to 12 seats, including the return of former MP Adam Price to frontline politics as the new AM for Carmarthen East and Dinefwr.
Most of the changes came with the results of the regional lists.
Joining UKIP Wales leader Nathan Gill on the North Wales list is Michelle Brown along with Tory Mark Isherwood and Plaid’s Llyr Gruffydd.
In South Wales East, Tory Mohammad Asghar and Plaid’s Steffan Lewis were also elected alongside UKIP duo Mr Reckless and David Rowlands.
In Mid and West Wales, UKIP’s Neil Hamilton was elected along with Simon Thomas of Plaid Cymru and Labour pair Joyce Watson and Eluned Morgan.
In South West Wales, Caroline Jones of UKIP was elected on the list with Plaid pair Bethan Jenkins and Dai Lloyd and Conservative Suzy Davies.
Ms Davies said: “We did make a dent [in Labour’s grip]. We didn’t quite take them [constituency seats] but we did reduce the Labour majority.”
In South Wales Central, UKIP’s lead candidate Gareth Bennett was elected, despite controversy over his blaming of litter in Cardiff on immigration.
Also elected were Tory leader Andrew RT Davies, his colleague David Melding, and Plaid’s Neil McEvoy.
Forty constituency seats and 20 regional seats were contested.
A party calling for the abolition of the Welsh Assembly came sixth in the regional list vote with 4.4% – 44,286 votes – ahead of the Greens on 3%.
Wales also went to the polls to elect four police and crime commissioners (PCCs), while a parliamentary by-election in the Ogmore constituency was won by Labour.
Counting for the PCC elections in Wales will take place on Sunday.
Hannah Blythyn (Lab, Delyn)
Dawn Bowden (Lab, Merthyr)
Rhianon Passmore (Lab, Islwyn)
Jayne Bryant (Lab, Newport West)
Vikki Howells (Lab, Cynon Valley)
Jeremy Miles (Lab, Neath)
Hefin David (Lab, Caerphilly)
Lee Waters (Lab, Llanelli)
Huw Irranca-Davies (Lab, Ogmore)
Adam Price (PC, Carmarthen East and Dinefwr)
Sian Gwenllian (PC, Arfon)
Nathan Gill (UKIP, North Wales)
Michelle Brown (UKIP, North Wales)
Mark Reckless (UKIP, South Wales East)
David Rowlands (UKIP, South Wales East)
Steffan Lewis (Plaid, South Wales East)
Caroline Jones (UKIP, South Wales West)
Dai Lloyd (Plaid, South Wales West)
Neil Hamilton (UKIP, Mid and West Wales)
Eluned Morgan (Labour, Mid and West Wales)
Gareth Bennett (UKIP, South Wales Central)
Neil McEvoy (Plaid, South Wales Central)
Analysis by Nick Servini, BBC Wales political editor
And so at the end of weeks of being told ‘it is time for a change after 17 years of Labour rule’, the people of Wales clearly came to the view that change can wait for another day.
This is a huge result for Labour. The most telling fact is that it successfully defended every marginal seat where it faced a Conservative threat.
The decision to place Carwyn Jones at the forefront of the campaign helped deal with the negative impression many people have of Jeremy Corbyn.
And, yes, the party may have ‘got lucky’ with the junior doctors strike in England, which helped blunt criticism of the Welsh NHS, but it knew how to handle the strokes of luck when they came along.
It was a very difficult night for the Conservatives who, above all, failed to capitalise on the momentum generated by their MPs in Wales last year.
It was also a mixed bag for Plaid. It would have been another disappointing night if Leanne Wood hadn’t won the Rhondda seat.
And then there’s UKIP. How active will they be in assembly politics? Nobody really knows what kind of party it will be after 23 June. If the AMs fail to play a full role then Carwyn Jones’ lack of an overall majority ceases to be a problem.