Newly elected United Kingdom Independence Party MP Douglas Carswell, left, poses with party leader Nigel Farage outside their office in Clacton-on-Sea in eastern England on Friday. Reuters

LONDON—Prime Minister David Cameron ’s Conservative Party sought to counter the electoral success of the U.K. Independence Party by issuing a fresh warning Friday that a vote for the right-wing rival would make it easier for the main opposition Labour Party to win May’s general election.

Results announced by electoral officials early Friday confirmed UKIP had won its first elected seat in the U.K. parliament in a contest held in the previously Conservative coastal town of Clacton-on-Sea.

UKIP, which wants Britain to leave the European Union, came a close second to Labour in another by-election in the northwestern constituency of Heywood and Middleton

UKIP’s success highlights the growing threat it poses to the two largest parties, with just seven months to go before the nation goes to the polls. While it remains small, it could drain support from the established parties in closely-fought seats.

In Clacton, Douglas Carswell, who had held the seat for Mr. Cameron’s Conservative Party since 2005 but defected to UKIP in August, took 21,113 votes, or 60% of the total cast during the contest on Thursday—which was also Mr. Cameron’s birthday. Although Labour won in Heywood, in its traditional heartland, the results were a close call—Labour attracted just 617 more votes than UKIP.

The Conservatives on Friday sought to shore up support from voters considering voting for UKIP. “Last night proved a simple truth: while UKIP say they take votes from all parties, they cost the Conservative Party seats,” said Conservative Party Chairman Grant Shapps in an email to party members. “That means a vote for UKIP puts Labour closer to winning the election and [Labour leader] Ed Miliband closer to Number 10,” Mr. Shapps said.

Mr. Shapps wasn’t immediately for available for comment. Mr. Cameron and the Conservatives have argued that theirs is the only party that has a chance of winning the election that is offering a referendum on Britain’s EU membership.

Mr. Miliband criticized the Tories, saying they had lost in their own backyard in Clacton and were in retreat in the northwest. However, the Heywood vote suggested Labour are also vulnerable to UKIP which is making a concerted effort to woo blue-collar voters.

“There won’t be a shred of complacency from us as we reach out to all those voters who didn’t vote Labour and those who didn’t vote at all,” Mr. Miliband said in an interview with the British Broadcasting Corporation.

U.K. voters frequently take advantage of midterm by-elections to register displeasure with incumbent parties, making the contests an unreliable guide for what will happen at a general election. Nevertheless, UKIP’s Clacton victory is likely to boost the party’s credibility with its first elected representative in Westminster and give it a national platform ahead of 2015.

The focus now shifts to a by-election in Rochester and Strood, a constituency in England’s southeast, where another former Conservative lawmaker, Mark Reckless, is due to stand as a UKIP candidate. The contest, which is expected to take place in a few weeks’ time, will be closely watched to see if UKIP can replicate its success. Messrs. Reckless and Carswell both hailed from the vocal and rebellious euroskeptic wing of the Conservative Party, many of whom believe the U.K. is better off outside the EU.

A poll published last weekend suggested UKIP could win in Rochester. That was given added impetus on Friday by bookmakers Paddy Power, which slashed the odds on a UKIP win in the southeastern constituency. It cut the odds of Mr. Reckless winning to 2-to-7 from 4-to11. The bookie also reduced its odds on other UKIP target seats in the May general election including South Thanet, where UKIP leader Nigel Farage is planning to run.

However, while the electorate of Clacton, with its high proportion of elderly and working class voters, was seen as fertile ground for UKIP’s tough stance against the EU, immigration and political establishment, Rochester is seen as more socially mixed and is likely to present a bigger challenge. Mr. Cameron has said it is a “vital” by-election campaign for the Conservatives.

Mr. Farage, in an interview with The Wall Street Journal Friday, said it had been a good couple of days for UKIP and, while confident, he acknowledged Rochester was a tougher battle on paper. The UKIP leader was heading to Rochester on Saturday to canvas voters there all weekend in what the party leader described as a “tough, take-no-prisoners campaign.”

Thursday’s by-elections showed there was a desire for change from the main three political parties led by career politicians, Mr. Farage said. Voters felt let down by the ruling class and had seen their communities change beyond all recognition as a result of open-door EU immigration, among other complaints, he said.

Write to Nicholas Winning at