The Lib Dems have claimed victory in the Eastleigh by-election, with the official result yet to be announced.
The party's candidate, Mike Thornton, told reporters he thought he had won.
The UK Independence Party's candidate, Diane James, said she was "still aiming for first", but now believed she was "guaranteed" second place.
The by-election was triggered by the resignation of former Lib Dem minister Chris Huhne, after he pleaded guilty to perverting the course of justice.
It was the first time the Conservatives and the Lib Dems, as coalition partners, have gone head-to-head in a seat which was winnable for both.
BBC political correspondent Robin Brant, who is at the count in Eastleigh, said that turnout was estimated at 52% - down from 69% at the 2010 general election, but still "high for a by-election".
"It's early days, but there is talk here of UKIP coming second and the Conservatives slipping to third," our correspondent added. "That would be virtually a victory for them."
Earlier, on the BBC's Question Time programme, Liberal Democrat Home Office Minister Jeremy Browne said he was optimistic the result would show that his party is "alive and kicking, and an important part of the political landscape of this country".
"We had the best candidate, I think that was accepted even by those who didn't vote for him," he claimed.
Mr Thornton has been a parish and borough councillor since 2007 and has lived in the local area for 19 years.
But the Conservatives' Claire Perry, appearing on the same programme, was worried that politicians visiting the seat had "overwhelmed the electorate" with campaign literature.
Residents had distributed leaflets yesterday saying 'Just go away, I've made my mind up', she said.
The Conservative by-election candidate, Maria Hutchings, stood against Chris Huhne in 2010, coming second. She lives in Eastleigh with her husband and four children and is a campaigner for special needs children and carers.
Mrs Perry said: "I would love to see more fantastic women in parliament, frankly across all parties. If we don't get Maria in, we're missing a chance to get a really great female candidate. So I'll be disappointed if we haven't won."
From the Hampshire constituency's creation in 1955 until 1994, Eastleigh was represented by the Conservatives. It has been held by the Lib Dems since.
Huhne won the seat in 2010 with a majority of 3,864 over the Conservatives, with Labour in third and UKIP in fourth.
Also on Question Time, UKIP's Neil Hamilton, a former Conservative MP, said his party had "everything to play for".
"My message to the other parties for 2015 is: Get used to UKIP, because we will be providing the real choice in the general election in 2015," he said.
UKIP's candidate, Diane James, is a healthcare expert and member of Waverley Borough Council in Surrey.
Were Mrs James to have edged the Conservatives into third place, Labour frontbencher Maria Eagle said there would be "meltdown in the Conservative party".
She said: "There's no doubt that immigration has been a big issue in the campaign here.
"We've had discussions about what we could do to deal with that, to ensure that no foreign worker should take a job at less than minimum wage and be exploited and force down people's wages".
Labour selected comedy writer, broadcaster and author John O'Farrell as its candidate.
This will be only the fifth occasion since the 1945 general election when the Lib Dems, or their predecessors the Liberals, have defended a parliamentary seat in a by-election.
Both coalition parties have been fighting hard to win the seat, with David Cameron and Nick Clegg visiting the constituency to campaign.
The Lib Dem leader has said he expects it to be a "close contest" and Mr Cameron had urged all his MPs to head to the constituency to support their candidate.
UK Independence party leader Nigel Farage has said he is expecting a "big swing" to his party in the seat, with most polls carried out in the seat putting the party third, ahead of Labour.
Labour's candidate, Mr O'Farrell, has said the campaign "re-invigorated" the party in the area, which Ed Miliband has visited to campaign several times.
Chris Huhne resigned as Eastleigh's MP earlier this month after pleading guilty to perverting the course of justice over claims his former wife took speeding points for him.
Since the start of the by-election campaign, the party has faced further difficulties with former Liberal Democrat chief executive Lord Rennard facing allegations of sexually inappropriate behaviour by female Lib Dem activists.
Lord Rennard has denied the allegations, which he described as a "distortion" of his character.
Lib Dem deputy leader Simon Hughes told the BBC that the allegations had not had much impact on Eastleigh voters, who understood that they were simply being asked to choose a new MP.
"The electorate are clever enough to realise that all the national stuff - that may be scandal or intrigue, or rumours or speculation - is not as relevant as who will go and fight for the sort of things that Eastleigh needs," he said.
Fourteen candidates stood in Eastleigh:
- COLIN BEX - Wessex regionalists
- DAVID BISHOP - Elvis Loves Pets Party
- JIM DUGGAN - Peace Party
- RAY HALL - Beer, Baccy and Crumpet Party
- HOWLING LAUD HOPE - Monster Raving Loony William Hill Party
- MARIA HUTCHINGS - Conservative
- DIANE JAMES - UK Independence Party
- DR IAIN MACLENNAN - National Health Action Party
- KEVIN MILBURN - Christian Party "Proclaiming Christ's Lordship"
- JOHN O'FARRELL - Labour
- DARREN PROCTER - Trade Unionist and Socialist Coalition
- DANNY STUPPLE - Independent
- MIKE THORNTON - Liberal Democrats
- MICHAEL WALTERS - The English Democrats - "Putting England First!"