Theresa May launched a slick new government website on Thursday, promising a “plan for Britain”, but for the first hour or so it just displayed an error message.

Technical gremlins can attack at any time, but somehow the glitch felt symbolic of the prime minister’s week.

With a commanding lead in the polls, and fresh from a historic byelection victory, May is little troubled by Her Majesty’s opposition, but this week her grip on events appeared to slip, perhaps for the first time since she swept into No 10 unopposed last July.

The Three Brexiteers, Liam Fox, David Davis and Boris Johnson, toured the TV studios on Sunday to pave the way for the government’s anticipated victory in the House of Lords over Brexit.

With the rebellion in the Commons melting away, the government was confident that peers – having made their point – would cave in, allowing the Brexit bill to pass, and the government to get on with triggering article 50. As Monday dawned, the stage was set for a good day.

But May had reckoned without the audacity of the Scottish first minister, Nicola Sturgeon, who staged a political ambush that caught Downing Street off guard. Sturgeon convened a dramatic televised press conference in Edinburgh, in the grand surroundings of Bute House, her official residence, to demand a second Scottish independence referendum before the UK leaves the European Union.

May shot back with a terse video statement, accusing the Scottish first minister of playing political games. But it was Sturgeon who set the agenda, and the future of the union – not the fact the government had secured parliament’s consent for Brexit – that dominated the headlines the next morning.

Sturgeon has been building the case for an independence referendum since the morning after the Brexit vote last June, but she seized her moment, as speculation swirled that No 10 was preparing to trigger article 50, the formal process for leaving the European Union, on Tuesday.

Downing Street had never confirmed that date, and when it became clear later on Monday that it was no longer a runner, they denied it had ever been the government’s intention to fire the starting gun this week. But they had allowed the speculation to swirl unchecked, making it hard to avoid the perception that May had been blown off course.

And Sturgeon’s chutzpah wasn’t May’s only headache. Pressure continued to mount on the prime minister, including from within the cabinet, to drop the most controversial element of Philip Hammond’s budget – the increase to national insurance contributions for the self-employed.

May had defended the policy on the previous Thursday night in Brussels, in the face of a backbench backlash, saying she believed it would make the system fairer – though promising not to legislate for the changes until the autumn. At the time, party whips hoped that would allow time for the revolt to die down, perhaps with the help of some ameliorating measures in the autumn statement.

But by Wednesday, not only was it clear to May that she would face an uphill battle to get the changes past her own MPs, let alone the Lords, but some of her own ministers were privately expressing disquiet about having to publicly defend a policy they didn’t agree with. It was becoming clear the dissent was not dying away, and the government would have to spend precious political capital over the coming months, persuading MPs of the merits of the case.

May demonstrated that Sturgeon wasn’t the only politician who could be bold. Rather than let the disquiet rumble on for months, she told Hammond the measure would have to be dropped. A U-turn would be painful, but hopefully soon forgotten: a strategy one Whitehall insider described as “rip the plaster off”.

Shortly before prime minister’s questions on Wednesday morning, the Treasury issued a letter from Hammond to the Conservative MP Andrew Tyrie, chair of the treasury select committee.

The tone was one of defiance, rather than humility: Hammond continued to defend the policy. But he conceded that it appeared to breach the “spirit” of the Conservative manifesto, which promised to “commit to no increases in VAT, national insurance contributions or income tax” – a pledge the Treasury felt it had discharged, by legislating later that year not to make changes in the main NICs rate for employees.

Hammond received a rough ride from Labour MPs when he appeared in the Commons to explain the decision, with shadow chancellor John McDonnell urging him to apologise.

But his own side turned out in force to show their support. Some moderate Tories later warned of a deliberate attempt to take Hammond down a peg or two, by pro-Brexit MPs who feared his natural caution would influence the upcoming negotiations.

Soon after Hammond sat down, news began to emerge that the Conservatives’ election expenses scandal, which has been rumbling on for months with dogged reporting by Channel 4 news, had reached a damaging new level.

Twelve police forces have passed files to the Crown Prosecution Service, affecting up to 20 MPs, over the way in which the party accounted for campaign buses dispatched to different constituencies during the 2015 general election.

Affected MPs have been coping with the fallout for months, with some interviewed by police, with – they say – little backing from Tory HQ. The CPS will make a decision by June about whether charges will be brought.

On Thursday morning, the scandal widened further, with the publication of an Electoral Commission report fining the Conservatives £70,000 for misreporting of expenses during the 2015 campaign.

May can legitimately argue the irregularities didn’t happen on her watch, but some of her key advisers were involved in the campaigns now being scrutinised closely. The affected MPs believe her handpicked chairman, Patrick McLaughlin, should have done more to get a grip on the case.

No prime minister wants to appear at the mercy of events, and May chose Thursday morning, as the expenses scandal was making waves, to issue her formal response to Sturgeon. “Now is not the time” for a fresh independence referendum, just as the government enters talks about the UK’s future with the rest of the EU, she said repeatedly.

This carefully calibrated line is meant to play on Scottish voters’ concerns about the instability created by a fresh poll, while not closing the door to a referendum altogether. But Sturgeon, and the SNP’s Westminster leader, Angus Robertson, have still been able to present May’s approach as intransigent. “History may look back on today and see it as the day the fate of the union was sealed,” Sturgeon said, rising to the rhetorical occasion.

May’s plan for Britain got another airing on Friday, as she addressed Conservative members at their spring forum in Cardiff.

But this week has shown how hard it is for a prime minister with a small parliamentary majority and a divided party to implement her plans – even without reckoning for the pugnacious Scots and the taint of financial scandal.

Having brutally dispatched so many of team Cameron to the backbenches – not least the new editor of the Evening Standard, George Osborne – and with few genuine friends among MPs, she also lacks the reserves of loyalty leaders need to draw on in tough times. And that’s before the Brexit talks, perhaps the biggest challenge for the British state since the second world war, have even got under way.

As Anand Menon, director of Britain in the Changing EU, puts it, “they haven’t been tested yet in the full heat of battle, with competing demands, under time constraints, when the negotiations are going to pit one ministry against another”.

May hasn’t quite slid, as Vince Cable once said of Gordon Brown, “from Stalin to Mr Bean”, but her reputation as a safe pair of hands was questioned this week as never before.