Leading article: The Prime Minister's black week suddenly turns rosy

A by-election victory and a strong interview show Mr Brown's resilience

This is not a judgement anyone probably expected to hear, but it is correct for all that. The Prime Minister ends the week in a stronger position than he began it. In the early hours of yesterday morning, Labour won the Glasgow North East by-election with ease. On the Today programme a little later, Gordon Brown managed to sound more relaxed and conversational than normal as he put the complex and increasingly controversial case for Britain's role in Afghanistan.

No one would have prophesied a relatively rosy weekend to come when The Sun launched its vitriolic onslaught last Monday. No allegation is more serious than one that implies the Prime Minister is casual in his dealings with relatives of those who have died in Afghanistan. But the publication of Mr Brown's handwritten letter, with its almost illegible handwriting and apparently clumsy spelling, prompted widespread sympathy for the Prime Minister.

The crudity of The Sun's attack became the story, not the integrity of Mr Brown. That newspaper will now think twice before it hurls another grenade in the Prime Minister's direction, and this is a significant development, as it seemed to be gearing up to attack him with an indiscriminate swagger. In battles with The Sun, it is extremely rare for the victim to emerge the victor. Mr Brown did so this week.

The by-election victory, of course, should have been a formality. If Labour cannot win in the poorer areas of Glasgow, it cannot win anywhere. But that is what happened in July last year, when it lost to the SNP in a similar constituency. With the economy in recession and the SNP supposedly still enjoying a honeymoon as the minority rulers in Edinburgh, Labour's win was substantial. It increased its share of the vote compared with the general election.

One conclusion could be that the SNP might not be as big a threat to Labour in Scotland in next year's general election as some of its leaders had assumed. The result offered little comfort to the other parties either. The Conservatives are making little headway in Scotland under David Cameron and few disillusioned voters turned towards the Liberal Democrats.

It is a reflection of Mr Brown's precarious position that a newspaper attack and a victory in a safe seat constitute a good week. And it is true that it could all have ended quite differently. Had the by-election been lost, Mr Brown would not have gone anywhere near a microphone and his internal critics would have been queuing up to call on him to resign. Even now, there is no reason for Labour to get carried away – and no sign of it doing so either. An anxious gloom remains the prevailing mood.

The turnout in the by-election was a pathetic 33 per cent, suggesting that the party has problems galvanising its core vote. Nor will the general election be decided by what happens in Glasgow North East. National opinion polls are still dire for Labour, even if the Conservatives are not performing as well as they should be. Afghanistan becomes more challenging each week. The economy is still in recession and, as the election looms, unemployment will almost certainly be rising.

Still, the past few days have been significant. They make it less likely that Mr Brown will be removed before the election and harder for The Sun to lead the charge against him. They are also a vivid reminder, with their sharp twists and turns, of the Prime Minister's resilience. Politics is unpredictable and the outcome of the next election is still uncertain.