Farquhar was born at Newhall, Aberdeenshire, near Aberdeen in 1774 as the youngest child of Robert Farquhar and Agnes Morrison, his father's second wife. His brother, Arthur, two years his senior, rose to the rank of rear admiral in the Royal Navy, and received a knighthood for his distinguished services during the Napoleonic Wars. Farquhar joined the East India Company as a cadet at age 17. Shortly after arriving in Madras on 19 June 1791, he was promoted to a low-rank commissioned officer of the Madras Engineers on 22 June 1791. Two years later, on 16 August 1793, he became a lieutenant in the Madras Engineers.
Farquhar was Chief Engineer in the expeditionary force which took Malacca from the Dutch on 18 August 1795. On 1 January 1803 he was promoted to the rank of full captain. From 1803 he acted as Resident of Malacca, and was made a full major in Corps on 26 September 1811, before he was officially appointed Resident and Commandant of Malacca in December 1813; a position he held for several years, in charge of both civil and military offices, until the Dutch returned in September 1818. During his tenure here he assisted in missions around the region, including the British invasion of Java led by Governor-General Lord Minto and Sir Stamford Raffles in August 1811. He spoke Malay, married a Malaccan-French woman, Antoinette "Nonio" Clement (he had six children by her); and was popularly known as the Rajah of Malacca. They had a daughter Esther Farquhar, who married Francis James Bernard.
An engineer, his reputation was established by his long and successful term as Resident of Malacca, of which he was given charge when it passed into British hands from the Dutch. A task given him by the British Government was to demolish all the structures left by the former occupants; he blew up the fortifications with gunpowder but spared some of the other buildings, showing great intelligence.
With his long Malayan experience, and an intimate knowledge of Riau-Lingga politics, Major Farquhar was given the task to help Sir Stamford Raffles find a settlement on Singapore island. He helped negotiate the provisional agreement of 30 January 1819 with the local chieftain Temenggong Abdul Rahman of Johore; and the more formal Singapore Treaty of 6 February 1819, which Raffles signed with the Temenggong and His Highness the Sultan Hussein Mohammed Shah, confirming the right for the British to set up a trading post.
The next day, 7 February 1819, Raffles appointed Farquhar as Singapore's first resident to develop the colony according to a specific plan Raffles had drawn up, Farquhar was left to manage the colony when Raffles left, an absence eventually lasting four years. He was appointed the first British Resident and Commandant of Singapore, 1819–23. Farquhar took a more laissez-faire approach, which suited the local traders who had followed him there. In his new post, he quickly set about clearing the plain on the north-east bank of the Singapore River. Word of this new trading post soon spread and Singapore became a thriving cosmopolitan town. Communication with Raffles in Bencoolen and the East India Company in Calcutta were so poor that for more than three years, Singapore developed on her own with Farquhar at the helm.
On 9 May 1821, William Farquhar was promoted to the rank of lieutenant colonel. Despite his many positive achievements in the formative period of Singapore's development, he adopted measures in his administration which conflicted with Raffles' instructions, notably in allowing the erection of houses and go downs on the Padang and on the nearby banks of the Singapore River. His justification was that in the rapidly expanding settlement 'nothing is heard in the shape of complaint but the want of more ground to build on'.
However, when Raffles returned, he was furious to discover his plans had been neglected and that moreover local vices such as the trading of opium and slaves were being tolerated. He then dismissed Farquhar, who at first refused to leave, and later sued Raffles for tyrannical behaviour. The conflicts which arose during Raffles' final stay in Singapore in 1822–23, led to his dismissal on 1 May 1823, to be succeeded as resident by Dr. John Crawfurd. He remained in Singapore after that for a few months.
Despite his significant contribution to the early development of Singapore, not much is known and remembered of him by the locals. Even the little street named in his memory is gone.
Farquhar was awarded the rank of major general, and retired to Perth, Scotland, in 1829, where he bought two large recently completed Georgian houses (one for his brother, a naval captain) and built a billiard hall for the entertainment of his many friends. He married again, and died in 1839 at his home, Early Banks. He has a mausoleum in Greyfriars Kirkyard, Perth.
Between 1819 and 1823 Farquhar commissioned unidentified Chinese artists to illustrate local flora and fauna. This project resulted in 477 watercolours of plants, mammals, birds, reptiles, fish and insects found in Malacca and Singapore. These paintings played a pivotal role in revealing the region's biodiversity to Western naturalists, and are interesting in their blending of the stylised oriental manner with the realism of western art. The William Farquhar Collection of Natural History Drawings showing 141 of these illustrations, was published in 1999. A volume containing prints of all 477 works in the Farquhar collection was published by Editions Didier Millet and the National Museum of Singapore in 2010.
At a farewell dinner with the principal merchants and British inhabitants on 27 December 1823, Colonel William Farquhar was presented with a plate valued at 3000 sicca rupees as a farewell gift. Shortly after, he finally departed from Singapore for Malacca, Penang and Calcutta en route back home to England. Farquhar's popularity with the Asian and the European community of Singapore was attested to by Munshi Abdullah bin Abdul Kadir, in his Hikayat Abdullah.
One example was the moving account of Farquhar's departure from Singapore at the end of December 1823, which was confirmed by a report in one of Calcutta's newspapers, which states that on that day as he left, he was accompanied to the beach by most of the European inhabitants of the settlement as well as by 'a large concourse' of Asians of every class. As a compliment to him, the troops formed a guard-of-honour from his house to the landing place, and he embarked with the customary salute to his rank. Then many Asian boats accompanied him to his ship, the "Alexander", and as they sailed, some of the Siamese vessels fired salutes to him. Similar welcomes and tributes also awaited him up the Straits, in Malacca and in Penang.
He died in Perth, Scotland. On his tomb, there is the following inscription in block capitals: "Sacred to the Memory of Major General William Farquhar of the H.E.I.C.Service and Madras Engineer Corps who served in the East Indies upwards of 33 years. During 20 years of his valuable life he was appointed to offices of high responsibility under the civil government of India having in addition to his military duties served as Resident in Malacca and afterwards at Singapore which later settlement he founded. In all the stations which he filled he acquired honour to himself and rendered service to his country. He departed this life at Early Bank, Perth, on the 11th of May 1839, highly respected and deeply regretted by all who had the happiness of his acquaintance."
Farquhar Street, a former street in Singapore, was named after him. This street was located in the Kampong Glam area between Beach Road and North Bridge Road. It was expunged in 1994 due to street realignment and no longer exists.
Lebuh Farquhar (Farquhar Street), another street in Penang, Malaysia is mistakenly thought to be named after him. It is actually named after Robert Townsend Farquhar (no relation), Lieutenant General of Penang from 1804-05.
Farquhar is a fifth great-grandfather of Justin Trudeau, the 23rd Prime Minister of Canada, and fourth great-grandfather of Margaret Trudeau.