The public message from David Cameron's extraordinary settlement of the dispute between Theresa May and Michael Gove is "team discipline". The line is that both are doing a marvellous job respectively cutting crime and improving educational standards, but that the prime minister needed to ensure that everyone was working together. Egos are duly deflated in the cause of teamwork.

The row itself was standard Whitehall blame-shifting: Gove briefed his old newspaper the Times that May and Charles Farr, head of the office of counter-terrorism, were lax on Islamist radicals accused of infiltrating Birmingham schools. The Home Office countered by posting on its website an interdepartmental letter accusing Gove of ignoring the problem for years. But the real dispute was about political power.

David Cameron has now, as the Tory press loves to put it, applied the firm smack of prime ministerial authority. He has made Gove write humiliating letters of apology to both Farr and the prime minister; he has made May sack her special adviser, Fiona Cunningham.

Downing Street's displeasure with Gove was made clear in the traditional manner: an unattributable press briefing from Downing Street pointing out that the minister was no longer untouchable, whatever his old friendship with Cameron. There was a chance – albeit not a probability – that he could be moved, in what is being billed as a "ruthless reshuffle". The story was briefed to the small-circulation Financial Times, and so was a shot across the bows.

The bigger loser of the two ministers is May. Gove has had to swallow his considerable pride, but nobody should go into politics unless they are adept at doing that. May, however, has lost one of her most trusted confidantes.

The Whitehall special adviser is the minister in absentia, speaking on behalf of, and with the assumed backing of, the secretary of state.

Power is lonely, and powerful people need loyal henchmen. It is not easy to find special advisers whom you know and trust implicitly, and who understand their minister's real goals and preferences and how they think.

The last time a prime minister forced a minister to sack a special adviser was when Tony Blair ousted Gordon Brown's mucker, Charlie Whelan, for leaking details of Peter Mandelson's mortgage. The relationship between Blair and Brown was already sour, but that instilled a bitterness into the feud that ultimately paralysed the government.

On that occasion, Brown was too important to be asked to apologise, although it was assumed that he knew exactly what Whelan was doing and was therefore in breach of the ministerial code. Sacking the minister's trusted messenger hurts the minister most.

May's loss of Cunningham will also change the ecology in the Home Office, since Cunningham has had a close relationship with Farr, one of the most ambitious, able and impressive Home Office civil servants. Farr is a key figure in Whitehall's deep state. He was a spy in Afghanistan for MI6 when John Reid promoted him, and he is now the linkman with GCHQ and MI5.

Farr has been an enthusiastic proponent of the communications data bill, even back in the last Labour government, when he briefed me as shadow home secretary. This is the proposed law that would provide a legal basis for sweeping up and analysing all email and telephone metadata – the information about who is contacting whom.

Farr is also, therefore, the civil servant who felt it was unnecessary to tell the Lords and Commons committee reviewing the draft bill that GCHQ was already sweeping up the metadata, which was only discovered thanks to Snowden's revelations in the Guardian. This failure shocked two former chief whips, David Maclean and Nick Brown.

There is a second, implicit message in David Cameron's swift put-down of his two colleagues. It is that he does not want to be fought over as if he were a warm corpse. He is not dead yet, and does not take kindly to infighting that suggests senior Conservatives are already jockeying for position post-Cameron. It looks defeatist, as it implies they agree with the bookies that the Tories are unlikely to win the general election.

Cameron will have been dismayed that polling has already begun about his successor, and will have noted both Gove and May in the frame as potential successors. However, the most dangerous rival is clearly May. Gove is a Cameron courtier who is still trying to build a base in his party. He is the jester to the Cameroons, with a great line in mimicry and good gossip.

May is much less fun. She is a tougher and more substantial figure in her own right. She is capable of the full range of political tactics from cool charm to unstoppable steamroller. And May tops the latest ConservativeHome succession poll, well ahead of Boris Johnson: all the more reason for the prime minister to do real damage to her, rather than merely symbolic damage.

If that leadership contest were to get out of hand, the prime minister would begin to look like a lame duck. Decisions that might go to him would instead be saved for the next leader. Political power depends crucially on momentum, and this is the prime minister's attempt to maintain it. The real lesson, though, comes not from Cameron's reaction but from the original spat. The most senior Tories now think power is ebbing away from the prime minister.