I admit, my knowledge about Malta is pretty thin. I know the Knights of Malta had it for ages, and then somehow the British have it by World War Two (and I think WWI).
So how did a country not even that close to the Mediterranean somehow get Malta?
Apologies for I have only just come across this post - but as somebody who is both Maltese and a historian, I can definitely answer you on this :)
So yes as you say, Malta was held by the Knights of St. John (also known as the Knights of Malta) for quite a while - from 1530 to be exact. The Knights were a very conservative and religious type of organisation with holdings all across Europe, but it was politically based in Malta which was convenient as it was a very strong naval power. There is a whole debate over whether the Knights were in decline by the late 1700s, but that is separate from your question - what is certain is that the French Revolution had severely affected it and, more importantly, its finances. Most of the Knights' property was in France - property which, naturally, was seized by the revolutionaries because of the Knights' ties with the Ancien Regime.
By May 1798, a young Napoleon was getting ready to hop over to Egypt for a military campaign there - and Malta was seen as a good acquisition which could be made on the way. He detailed this in a letter to one of his generals which was only recently discovered and acquired by the Maltese government. Long story short, Napoleon sailed into the Grand Harbour of Valletta with his fleet, with the Knights barely even offering a whimper as resistance. The Knights were allowed to leave the island in peace and with honours, and the French subsequently took over the island and started to implement the republican reforms that had characterised France at that point.
Now - we have to keep in mind one thing: the Maltese people are fiercely devoted to religion. The Church was (and still is) a significant part of Maltese society and culture. However, this went contrary to the principles of the French revolution. The tipping point was when the French began to gut Maltese churches of their valuables, valuables which would be used to finance the expedition in Egypt. A Maltese 'army' of irregulars rose against the French on 2 September and - outnumbered - the occupiers found themselves locked into the fortified capital city of Valletta.
It was at this point that the Maltese formed their own National Assembly in order to decide the way forward. Messengers were sent out to a British fleet based in Sicily (let's keep in mind that the British had strong naval presence in the Mediterranean, as Napoleon found out to his own detriment in Egypt) asking for help in Malta in getting rid of the French - but it was only a whole year later that the British arrived and the French finally surrendered and were allowed to leave Valletta and Malta in general.
A man named Sir Alexander Ball was appointed as Malta's Civil Commissioner, and Malta became pretty much a British protectorate.
However, in the 1802 Treaty of Amiens between Britain and France, the British agreed to give Malta back to the Knights - but they never did (one of many cases of non-adherence by both the British and the French in that treaty).
However where do the Maltese come into the matter here? The notion of Malta and independence has always been a touchy one - even in the 1960s the two major political parties in the country did not want independence as their first choice for the country's future - they only both agreed to it after their first choices (dominion status with the UK and integration with the UK respectively) did not pan out. Likewise in 1802 - a declaration was penned by 104 representatives of Maltese society which basically set out that they recognised George III as the ruler of Malta and that he had no right to give Malta to anyone else. The declaration essentially read that Malta wanted to have self-government, however under British rule.
Long story short, when the Treaty of Amiens eventually collapsed in on itself, the British remained in Malta - but it wasn't before 1813 (13 years after they first arrived) that Malta was formally declared a colony rather than a protectorate - which was recognised in 1814 and 1815 by the Treaty of Paris and the Treaty of Vienna respectively.
And so, Malta remained a British colony for the 151 years that followed - including World War One and World War Two as you rightly point out, when it played significant roles - before obtaining independence in 1964.
If you've got any more questions about anything related to Malta just drop them here or as a post and I'll be more than happy to answer!