The shift from a hereditary monarch to an elected Prime Minister was a long evolution in British history. Monarchs like Henry VIII had a chief adviser like Thomas Cromwell who were regarded as the head of government. But they were responsible to the King not to Parliament for their power.
The English Civil War and the Glorious Revolution in the 17th century significantly shift power from the King to Parliament. The Monarch can no longer make laws or raise taxes without their consent. The Bill of Rights of 1689 limited the Monarch's powers and guaranteed regular and free elections to Parliament, and free speech to its members.
The shift accelerates in 1721 with the accession of George I to the Throne. George was German, spoke little English and preferred to live in Hanover to London. As a result of an absent King, Sir Robert Walpole was quite obviously the head of government, first in partnership with Townsend and then on his own. Walpole chaired Cabinet, appointed the other Ministers, and managed the politics to maintain a majority of support in Parliament through patronage. However, Walpole also rejected the term Prime Minister and in fact it only acquired general use more than a century later.
There was an attempt by George II and George III to reassert the power of the Monarch. George II favoured another for the role of head of government. However, Walpole commanded a strong majority in Parliament and the new King kept Walpole to maintain stability. George II is seen as somewhat weak and ineffective, but his son was more formidable.
George III chafed at having to appoint a Prime Minister based on the majority in Parliament. He clashed openly with some of his Ministers, particularly Charles James Fox, and involved himself directly in politics. For instance, when Fox introduced an act on the East India Company the King disliked, he let it be known that the King would regard any Lord who voted for the Bill as an enemy. The King then dismissed the administration.
Subsequently, William Pitt the Younger became PM, a coup for the King who was a supporter of many of Pitt's policies. While George's role in politics was admonished by Parliament, Pitt was elected with a strong mandate in the subsequent election. This is an important development and strengthened the King's hand as he believed his actions were validated by the electorate. Pitt and the King were allies countering Fox and the Prince of Wales. George III provided direct political support to the PM, including appointing a large number of new Lords in order to strengthen Pitt's hand there.
However, George III suffered from a mental health condition that incapacitated him several times during his reign. As a result, power consolidated itself with Pitt. But Pitt was most certainly not the first modern Prime Minister. He did not head a consolidated political party so much as was in partnership with the King. He left office in 1801 because his policies were not to the King's liking and returned to office on the King's terms. Pitt strengthened the role of Prime Minister but did not surpass the King in political power. Rather, Pitt assumed the other partners role in the enterprise during the King's long illnesses and could not have stayed in office without the King's support.
The final shift between King and Prime Minister takes place later. William IV was the last to dismiss a Prime Minister against the will of Parliament. During the Reform crises of 1831-32, William refused to appoint more Lords after the Reform bill was defeated there. Instead he accepted the resignation of the Whig government and attempted to appoint Wellington. But when Parliament would not back the Tory, he was forced to bring back the Whig Grey and agree that he would appoint the Lords if the House of Lords remained a problem. The resulting passage of the Reform Act shifted power from the Lords (appointed by the Monarch) to the Commons (elected by the people) and as such, further empowered the Prime Minister. It was now the popularly elected Chamber that was supreme, not that appointed by the Monarch.
The true moment when the Prime Minister became more power was when William IV dismissed the Melbourne government because the PM attempted to make Russell the Chancellor, a figure the King saw as too left-wing. At the King's request, the Tory Peel attempted to form a government but found it was impossible with a Whig majority. After an election, Peel still lacked a majority and Melbourne was returned to office. This was the critical moment. Previously, when a King dismissed a government and a new administration sought a mandate in an election, the people could be expected to vote in supporters of that administration. However, with the Melbourne dismissal, the people did not do this. It showed that the Monarch's ability to move public opinion, and therefore national policy, was insufficient to dismiss an administration over the objections of Parliament.
Shortly thereafter, William IV died and Victoria's reign began. Victoria did not attempt to dismiss a Prime Minister after the experience of her predecessor, and her own inexperience and youth in beginning her reign at just 18. Rather than attempt to assert her will over the Prime Minister, Melbourne became her advisor in politics. She reportedly said he was like a father to her, and Melbourne's own child had died at a young age. The Prime Minister spent up to four hours a day tutoring the young Queen in the art of government. As a result, Victoria became reflexively Whig in her politics.
This partisanship led to the final act of a Monarch usurping Parliament. The 1839 "Bedchamber Crisis" began when Melbourne only narrowly won a key vote, and saw his support was slipping away. When Melbourne resigned and Peel was asked to form a government, the new Tory PM requested that the Queen dismiss her "ladies of the bedchamber," her attendants many of whom were wives of Whig MPs. Victoria refused, Peel used it as an excuse to avoid taking over a minority government that could damage his future prospects, and Melbourne returned to office. In essence, Victoria was the last Monarch to keep a Prime Minister against the majority of Parliament.
Shortly after, Victoria wed Prince Albert. The Prince Consort became Victoria's closest advisor and aided the final supremacy of constitutional monarchy. In 1841, Victoria accepted Peel as Prime Minister and accepted the "wise advice of the democratically minded Prince Albert" in replacing three of her Whig ladies with Conservatives.
In 1848, revolution was rocking Europe and Albert feared for the lives of relatives. But the royal families protests of Palmerston's independent foreign policy in support of the revolutions were limited by their support for the limits of constitutional power. By 1867, constitutional scholar Walter Bagehot wrote in his masterwork "The English Constitution" that the Monarch only retained the "the right to be consulted, the right to encourage, and the right to warn." Government became the realm of professionals and no longer those born to the office.
Sources:
Bagehot, Walter. The English Constitution. (1867).
Bogdanor, Vernon. The Monarchy and the Constitution. (1995).
Brown, David. Palmerston. (2010).
Duffy, Michael. The Younger Pitt. (2000).