Ukip leader Nigel Farage has said he believes Britain has voted to remain in the European Union, but declared: "Win or lose this battle, we will win this war."
Speaking as votes in the EU referendum were being counted across the country, the leading Brexit campaigner told supporters: "The Eurosceptic genie is out of the bottle and it will now not be put back."
Other senior Leave figures declined to back Mr Farage's assessment, which he told the Press Association was based on information from private exit polls conducted by friends in the City, as well as his personal sense of how referendum day had gone.
But the first result to be announced in the UK gave only a slender lead of 50.7% to 49.3% for Remain in Newcastle-upon-Tyne, which had been expected to give a more enthusiastic thumbs-up for EU membership.
With no exit polls conducted by broadcasters, a reliable picture of the likely outcome was not expected to emerge until the early hours of Friday, with the final result expected at breakfast time. But the final poll of the campaign forecast a Remain victory by a margin of 52% to 48%.
Meanwhile, Conservative supporters of Brexit including Boris Johnson and Michael Gove wrote to David Cameron urging him to stay on as Prime Minister regardless of the result, as Tories battled to restore a unity riven by weeks of divisive "blue-on-blue" fighting.
Some 84 Leave-backing Conservatives signed a letter to tell the PM: "We believe whatever the British people decide you have both a mandate and a duty to continue leading the nation implementing our policies."
As well as Mr Johnson and Mr Gove, the signatories included Cabinet-level Brexit backers Chris Grayling, Theresa Villiers and John Whittingdale.
But former Cabinet ministers Owen Paterson, Cheryl Gillan and David Jones, along with influential backbenchers David Davis and Bernard Jenkin, did not sign.
Former work and pensions secretary Iain Duncan Smith, who quit the cabinet weeks before the referendum, did not sign but said he thought Mr Cameron should stay.
Tory MP Robert Syms said that two-thirds of Conservative MPs who broke with the PM to back Leave had signed the letter, but said it had not been possible to reach all of them to ask them to sign.
Labour's Jonathan Ashworth said the Conservative Party was "utterly preoccupied with leadership infighting rather than the future of the country", adding: "This letter cannot unsay what senior Tory politicians have been telling us for weeks - that the British people simply cannot trust David Cameron."
Sterling rose 1% against the US dollar in overnight markets amid speculation that Remain has won the referendum.
Speaking at a party hosted by the Leave.EU campaign for Brexit, Mr Farage said the balance may have been tipped by the two million additional voters who registered after the deadline for applications was extended by 48 hours after an official website crashed.
He said the EU was "doomed" whether the UK left or not, adding: "Win or lose this battle tonight, we will win this war. We will get our country back, we will get our independence back and we will get our borders back."
But the Brexit campaign received a boost in Sunderland, where 82,394 voted for Leave, against 51,930 for Remain.
And Leave.EU said that it had conducted an "internal poll" of 10,000 people which suggested that Brexit was leading by 52% to 48%.
Environment Secretary Liz Truss said she was "optimistic" about a positive result for Remain while Education Secretary Nicky Morgan said she was "confident and hopeful" of victory for the In camp.
And pro-Brexit Northern Ireland Secretary Ms Villiers told Sky News: "My instinct is that Remain has won ... I suppose I would put it down to Project Fear succeeding."
However, she said it was "crucial" whatever the vote that Mr Cameron stays on as Prime Minister because the UK will need "political stability".
Mr Grayling said it would be an "absolute nonsense" for Mr Cameron to lose his job given that he won an election just over a year ago promising to hold a referendum.
"It would be an absolute nonsense if David Cameron felt, having given the country that choice, if they take the decision he couldn't carry on the job," he told Sky News.
"We are completely behind him staying, we want him to stay and that letter is a statement of commitment to his leadership."
A high turnout was expected in the referendum, despite torrential rain in South-East England which forced the closure of some polling stations and caused transport disruption for commuters planning to vote on their way home.
A record 46,499,537 voters were eligible to take part, said the Electoral Commission, meaning that a turnout a little over 72% could surpass the highest number of ballots cast in a general election.
Gibraltar, which is taking part in the referendum as a British overseas territory within the EU, was the first area to declare with an overwhelming victory for Remain by 19,322 to 823 on a healthy turnout of 84%. And the Orkney Islands also backed continued EU membership by a margin of 7,189 to 4,193.
Press Association analysis of early turnout figures suggested that either camp will need a total of around 16,400,000 votes to pass the winning post.
A Labour source said: "There has been a strong turnout, higher than the general election in many areas. Early indications showing more divergence than we expected – bigger leads than expected for Remain in likely Remain areas but also bigger leads for Leave in likely Leave areas."