Jeremy Corbyn successfully passed his first electoral test with flying colours but Ukip complained of a "bent" contest after failing to make the breakthrough it hoped for in the Oldham West and Royton by-election.
Jim McMahon held the seat for Labour with a majority of more than 10,000 and an increased share of the vote.
The result will come as a major relief to Mr Corbyn after a torrid week for his leadership following bitter in-fighting within Labour over air strikes in Syria.
The Labour leader hailed the result as a "vote of confidence in our party".
Turnout was higher than expected at just over 40%, and Labour's success appears to have been secured with an effective postal vote operation - a factor seized on by Ukip.
Party leader Nigel Farage said: "As a veteran of over 30 by-elections I have never seen such a perverse result. Serious questions need to be asked."
The Ukip leader claimed to have "evidence from an impeccable source that today's postal voting was bent".
Mr McMahon, the leader of Oldham Council, said: "I am delighted to have been elected tonight. Michael Meacher was a close friend of mine and he was admired by people across the country as someone who worked tirelessly for the causes he believed in. I will do my best to live up to those high standards.
"My sole focus has always been on what is best for Oldham, I want to make our town a better place for my sons to grow up in and make it somewhere they can be proud of, my priority will always be Oldham.
"We also need to remember what is currently at stake under this Tory government. While everyone is looking the other way they are quietly pushing through cuts that will change the face of towns like Oldham.
"The sooner we kick the Tories out and get a Labour government back in, the better for all of us. The hard work starts now."
Mr McMahon dismissed Mr Farage's accusations of irregularity, telling the BBC: "Ukip just need to understand that people have the right to vote for the party that best represents their interests.
"I can say with confidence that we represent every community in Oldham and every community came out and voted Labour."
Mr Corbyn said: "Jim McMahon will make an excellent MP and a worthy successor to Michael Meacher, and I am looking forward to welcoming him to Labour's team at Westminster.
"Jim ran a great campaign, focusing on bringing jobs to Oldham and giving every child the best opportunities.
"By-elections can be difficult for the party holding the seat, and turnouts are often low. But to increase our share of the vote since the general election is a vote of confidence in our party.
"It's a clear demonstration that Labour is the party working people trust.
"Our determination to oppose Tory austerity policies, and our successes in pushing them back on tax credit and police cuts show that Labour is getting results for working people.
"With the Tories going nowhere in Oldham, Ukip has benefited from a protest vote. But this first electoral test in the new parliament has made clear Labour is the real alternative for Britain."
Mr McMahon polled 17,322 votes, with Ukip's John Bickley trailing in second on 6,487, a majority of 10,837.
Labour's share of the vote increased by more than seven points to 62.7% and there was a 2.39% swing from Ukip to Labour.
Tory James Daly was third with 2,596, 9.33% of the vote, while the Liberal Democrats lost their deposit after Jane Brophy secured 1,024 votes, a 3.68% share.