Ed Miliband has pledged to learn lessons from Labour's shock by-election defeat in Bradford West.

The party lost its grip on the constituency after Respect MP George Galloway swept to victory with a majority of more than 10,000.

The Labour leader said: "It was an incredibly disappointing result for Labour in Bradford West and I am determined that we learn the lessons of what happened. Clearly there were local factors, but I also say only four out of 10 people voted for the three mainstream political parties. We've got to understand the reasons why that happened in Bradford.

"Above all it reinforces for me something that I've emphasised throughout my leadership which is that we need to be engaged and rooted in every community of this country. We need to show to people that our politics, that Labour politics, can make a difference to people's lives."

Labour was predicted to hold on to the seat, but Mr Galloway, an ex-Labour MP, won 18,341 votes to the 8,201 for Labour candidate Imran Hussain. The contest was sparked by the resignation due to ill health of Marsha Singh. Turnout in the poll was just over 50% - considered high for such an election, especially in an urban area.

As he did in the 2005 general election, when he dramatically swiped an east London seat from his former party, Mr Galloway targeted the votes of a large Asian community.

Celebrating his victory, he told Sky News: "It is a very comprehensive defeat for New Labour, it is a pathetic performance by the Government parties. The big three political parties have had a very salutary, unkind lesson this evening and I hope that they all take note. The people of Bradford have spoken this evening for people in inner cities everywhere in the United Kingdom."

The Conservatives polled 2,746 votes, suffering a swing of 22.78%, but party chairman Baroness Sayeeda Warsi attacked Mr Miliband for failing to capitalise on the Government's recent difficulties over a potential strike by fuel tanker drivers, the furore over the so-called pasty tax and the "cash for access" row.

Shadow chancellor Ed Balls took to the airwaves to defend his leader, claiming the party was "winning back our heartland voters". Mr Balls took part in a phone-in on BBC Radio Leeds where a caller named Jamie accused Labour of fielding an Asian candidate to appeal to Asian voters, saying: "People see through that now. You have to put good candidates up if you want to get votes. You can't just rely on putting a Pakistani candidate up, thinking you're going to get all the votes."

But Mr Balls said Mr Hussain was chosen through a proper selection process, adding: "The reality is he lost, George Galloway won and we are a democracy and in politics the voters choose."