Jeremy Corbyn has said Labour's by-election loss shows "the scale of how hard our task is to persuade people of our message".
In a speech, he urged his party to "remain united", and not to "give up".
Labour lost the seat of Copeland, in Cumbria, to the Conservatives last week - the first by-election gain by a governing party in 35 years.
Tory chairman Sir Patrick McLoughlin said it had been a "fantastic result" for Prime Minister Theresa May.
Labour's deputy leader, Tom Watson, accused some of Mr Corbyn's "cheerleaders" of "peeling away from him" during a difficult time.
While the party lost in Cumbria, the party managed to hold off a challenge from UKIP in a by-election, in Stoke-on-Trent Central, on Thursday.
In his speech to the Scottish Labour Party conference in Perth, Mr Corbyn said: "The policies and ideas we are setting out are policies whose time has come. But to win that fight we need to remain united."
But Mr Corbyn, Labour leader since 2015, said: "The scale of how hard our task is to persuade people of our message was underlined just this week in Copeland.
"Whilst we stood up to hatred and division in Stoke, I cannot lie and say the result in Copeland was what we wanted. But now is not the time to retreat, to run away or to give up."
Mr Corbyn called losing Copeland - which had been held by the party since its creation in 1983 - "deeply disappointing" and added that he took "my share of responsibility".
Questioned about his future after the speech, Mr Corbyn said: "I'm carrying on as leader because I'm determined that we will deliver social justice in this country."
Asked if he would still be in place in 2020, when the next general election is expected to take place, he replied: "I've given you a very, very clear answer - yes."
Speaking on BBC One's Andrew Marr Show, Sir Patrick McLoughlin said: "Copeland was a fantastic result for the prime minister."
He added: "It shows that all seats are seats that we will look at, and we are going to challenge hard at the general election."
Meanwhile Tom Watson, told ITV1's Peston on Sunday the team who got Mr Corbyn elected for a second time "seem to be peeling away from him" and he queried where Unite union general secretary Len McCluskey was at this "difficult time".
He said it should not just be up to him to defend Mr Corbyn, but a Unite spokesman said that as Labour's deputy leader it was "his job to address the issues facing the party in the wake of the by-elections."
"Len McCluskey's job is to address the issues that are the foremost priorities for Unite's members," he added.