Voting has closed in the battle between Jeremy Corbyn and Owen Smith for the Labour Party leadership. Here's a guide to the contest, and what sparked it.
Labour leadership election timetable
- 19-20 July: The number of MP nominations for each candidate was published
- 20 July: Deadline for people to sign up as a registered supporter closed
- 22 August: Ballot papers began to be sent out in the post and by email
- 21 September: Deadline for votes to be received closed
- 24 September: The result is announced at a special conference in Liverpool
Who could vote in Labour leadership contest?
Labour Party members, affiliated trade union supporters and so-called registered supporters were able to vote, although there are some key differences from the 2015 contest which Jeremy Corbyn won.
- Labour Party members needed to have signed up on or before 12 January to be eligible to vote. At least 130,000 people became members in the wake of the EU referendum. They were not able to vote unless they also paid to become a registered supporter
- Anyone wanting to become a registered supporter - giving them a one-off vote - needed to pay £25 and "share" Labour's aims and values. There was a two-day window for people to sign up, which ended at 17:00 BST on 20 July
- Registered supporters who paid £3 to vote in last year's leadership election had to register again and pay the higher amount to be eligible to vote
- Affiliated trade union or socialist society supporters could sign up for less than £25, with rates depending on the organisation they belong to, but they had to have joined an affiliated organisation before 12 January, and then needed to register before 8 August
Who are the candidates?
Jeremy Corbyn took the political world by surprise when he romped to victory in last year's Labour leadership contest, having begun the contest as a rank outsider.
He enjoys strong support from many Labour Party members but he does not command the confidence of the majority of his MPs, losing a vote of no confidence by 172 to 40.
The vote was triggered by Labour MPs unhappy with Mr Corbyn's leadership and critical of his "lacklustre" campaign to stay in the European Union.
A north London MP since 1983, he has long been a stalwart of the British left and spent his career on the backbenches fighting a rearguard action against Labour's abandonment of the radical policies and values contained in its 1983 manifesto, such as a commitment to renationalising the utilities and nuclear disarmament.
Mr Corbyn has been a virtually ever-present figure at demos and marches, a joiner of committees and a champion of - sometimes unfashionable - leftwing causes. He was one of the key figures in the Stop the War campaign against the Iraq War.
He began his education at the fee-paying preparatory school, Castle House, in Newport, before moving into the state sector, after passing his 11-plus.
He is a vegetarian and does not drink alcohol. He lives with his third wife and has three sons from an earlier marriage.
What has he said on Brexit? Trigger Article 50, the formal process for leaving the EU, straight away. "The British people have made their decision. We must respect that result and Article 50 has to be invoked now so that we negotiate an exit from European Union... There must be the best deal possible in order to ensure strong industries in Britain stay strong and strong industries that have big export markets protect retain those export markets. But we are in some very difficult areas."
First elected to Parliament in 2010, as the MP for Pontypridd, Owen Smith quickly rose up the party ranks, and was appointed a shadow minister for Wales within months.
In 2012 he was promoted to shadow secretary of state for Wales, before shadowing the work and pensions brief. But Mr Smith was one of a series of shadow cabinet members to recently resign over Jeremy Corbyn's leadership.
Mr Smith, 46, has been a Labour Party member since the age of 16, at which time he was a pupil at Barry Boys Comprehensive School in the Vale of Glamorgan, before moving on to study history and French at the University of Sussex.
A career in journalism at the BBC followed, where he plied his trade as a radio and a television producer. He left to take up a role as a government special adviser to former Torfaen MP Paul Murphy, principally at the Northern Ireland Office.
He has also worked as a lobbyist for pharmaceutical company Pfizer.
Mr Smith lives in the Pontypridd area with his wife, Liz, and their three children.
Launching his leadership campaign, Mr Smith pitched himself as the candidate that could unite the Labour Party. He has vowed to put tackling inequality at the heart of the party's mission.
Brexit position: He has suggested the possibility of a second referendum on EU membership, but said it would depend on what kind of deal the UK negotiated on the terms of Brexit. "I don't think we should accept we're on a definite path out. I think we need to make sure people are satisfied. We trusted people, rightly, to take the decision. We can trust them again in 18 months' time to check it's absolutely what they wanted."
Were there any other candidates?
Yes. Angela Eagle was first to throw her hat in to the ring and challenge Jeremy Corbyn, saying his leadership "was not working".
She withdrew in July and backed Owen Smith as a "unity candidate" after he gained more nominations from Labour MPs and MEPs.
The MP for Wallasey and twin sister of fellow MP Maria Eagle had said she could provide leadership "in dark times for Labour" and unite the party and the country.
What has she said on Brexit? It would "cause chaos" to trigger Article 50 straight away. "We need to spend more time disentangling ourselves from the European Union in a way which does the least damage. We need to be very focused on that… I wouldn't rush to the exits."
Who are the unions backing?
The two largest unions affiliated to Labour, Unite and Unison, have given their backing to Jeremy Corbyn.
However, Owen Smith has picked up support from two other major unions, the GMB and Usdaw.
Why is Jeremy Corbyn facing a leadership challenge?
Jeremy Corbyn has always had relatively little support among the party's 232 MPs. In last year's leadership contest candidates had to be nominated by 35 Labour MPs to go through to the wider vote of party members.
Mr Corbyn only managed to get the backing of that many after some Labour MPs - including London mayor Sadiq Khan - decided to nominate him to "widen the debate" by ensuring there was a left-wing Labour voice in the contest.
Although he was seen as the outsider in the contest, when it moved to the wider vote of party members and the new "£3 supporters", he surprised commentators and the party's top brass as he surged through to be elected Labour leader, with 59.5% of the vote.
That victory included overwhelming support from all the groups who voted in the contest - party members, affiliated supporters - including trade unionists - and registered supporters who rallied behind his anti-austerity message and promise of a new politics.
Under Mr Corbyn, Labour has won the by-elections in seats it has defended. But it has also had what was judged to be a disappointing set of results in May's elections around the UK.
The trigger for the move against him was the UK's vote to leave the EU. Labour rebels say they felt Mr Corbyn - the most Eurosceptic Labour leader for 30 years - had not shown enough enthusiasm and leadership during the campaign, despite arguing for a Remain vote.
Dozens of his frontbench team walked out after Hilary Benn was sacked on 26 June, saying Mr Corbyn cannot win a general election. The Labour leader has said he will carry on, replacing them with colleagues who are more sympathetic to his political views.
What are Jeremy Corbyn's allies saying?
Mr Corbyn's allies insist that he is "not going anywhere" and that he wants to lead the party into the next general election. They say that Labour should be focusing on opposing the government under new Prime Minister Theresa May rather than getting involved in internal party battles.
His allies said the vote of no confidence on 28 June, which he lost by 172 votes to 40, was "unconstitutional", arguing that his election victory last year gave him the biggest mandate of any opposition Labour leader in history. They say he is more in touch with Labour voters' views on a range of issues, including the economy, defence and Europe, than MPs in the centre and centre-right of the party.
Mr Corbyn has urged people to "unite" behind him at a critical moment for the country, saying he was democratically elected "for a new kind of politics by 60% of Labour members and supporters" and that he will "not betray them" by resigning.
The next general election is not due to take place until 2020. Theresa May has said she will not call an early election, but she may yet face pressure to do so - potentially within the next year.
Can a sitting leader of the party be challenged?
In short, yes - but there are hurdles to overcome.
Anyone wishing to challenge a Labour leader needs the backing of 20% of Labour MPs and MEPs. Currently there are 231 Labour MPs and 20 Labour MEPs so any potential candidate needs the formal support of 51 of them.
They have to write a letter to Labour's general secretary, currently Iain McNicol, announcing an intention to stand.
Why was Mr Corbyn automatically on the ballot paper?
The party's National Executive Committee decided by 18 votes to 14 that Jeremy Corbyn should be automatically included on the ballot in Labour's leadership contest.
This meant he did not need to secure MPs' backing.
However, some anti-Corbyn factions in the party believe he should not automatically have been allowed onto the ballot.
They pointed to a Times article in November 2015 which reported legal advice had been sought by the party and it suggested a sitting leader would need to receive nominations from MPs and MEPs in order to stand again.
Labour donor and former parliamentary candidate Michael Foster launched a legal challenge to the party's ruling to put Mr Corbyn automatically on the ballot - but it was rejected by the judge.
The only time since 1945 that a sitting Labour leader has been challenged was in 1988 when Tony Benn sought to topple Neil Kinnock. Neil Kinnock said he had to be endorsed by members of the Parliamentary Labour Party in order to get on to the ballot paper - which some argued had set a precedent.
Mr Corbyn said the electoral college system put in place in 1988 had been replaced by "one member one vote" and said the rules were "absolutely clear" that "the existing leader, if challenged, should be on the ballot paper anyway".
He called the court case a "waste of time and resources".