There are three parts to the British legislature. The Monarchy is the head of state, and the prime minister is the head of parliament. Parliament is made of two chamber, the more powerful House of Commons and the lesser House of Lords.
The UK electoral system operates through First Past The Post. The United Kingdom is divided into constituencies (there are roughly 645, but this changes every election). MPs from all the different parties who wish to run for election campaign to be the MP for a constituency. The citizens of that constituency on general election day then vote for the MP they want to be their MP. That MP then has a seat in Parliament.
It's called FPTP because it is the MP who has the most number of votes who wins the seat. At the end of the day the party who has the most number of seats in Parliament is the ruling party and forms the government. The leader of that party is now the prime minister. He is invited to the palace by the Queen, who in one of Britain's many traditions and conventions, asks them to be her prime minister. The second biggest party in the commons, forms the opposition.
Therefore, the british people hvaen't actually voted for the prime minister but only their local MP, which is why you can have changes in PMs mid-term, i.e. Gordon Brown.
Elections are called by the prime minister and can be called at any time, but no one party can rule for more than five years without calling an election. Four to five years is the norm for one term in office.
As an electoral system it provides very strong stable governments, as very rarely are there ever hung parliaments where coalition governments between two parties have to rule. However statistically it is very wasteful with votes.
Voter apathy is so great now that only 60% of the electorate actually vote for a party. Because for an MP to succeed he/she needs only the greatest number of votes not the majority, often winning parties don't have 50% of the total vote. Indeed in 2005, Labour received only 35% of the vote overall, which means that 65% of the voting electorate didn't want him in power. As only 60% voted in the first place, only about 20% of the country wanted him to be their PM.
I hope this helps! For more detail google 'the UK's First Past the Post electoral system', which should help.