Born at King's Langley, Hertfordshire, on 21 January 1821, he was eldest of four sons of William Petrie, a War Office official, and his wife Margaret Mitton, daughter of the banker Henry Mitton, of the Chase, Enfield. In 1829 his father was sent to the Cape of Good Hope, where he acted until 1837 as deputy commissary-general, with as neighbour Sir John Herschel, the astronomer, who was a significant influence on the younger William Petrie's interest in science. After home education in Cape Town, Petrie, with his brother Martin, entered the South African College. In 1836 Petrie became a medical student at Cape Town Hospital, but next year the family returned to London and he went to King's College, London. Later he studied electromagnetism in Frankfurt. He returned to England in 1841, and took out a patent for an electric generator. From 1846 to 1853 Petrie worked on electric lighting problems with William Edwards Staite. He is credited with the invention in 1847–8 of a self-regulating arc lamp, with an automatic movement of one electrode. He superintended the manufacture of the new lamp at Charles Holtzapffel's works in Long Acre, London. On 28 November and 2 December 1848 Petrie made displays with a lamp of 700 candlepower from the portico of the National Gallery, and on nights in 1849 from the Hungerford suspension bridge in London. The demonstrations were witnessed by Charles Wheatstone, among other scientists. Petrie and Staite's efforts to promote electric illumination were, however, financially disastrous, absent better generators. Subsequently Petrie turned his attention to electrochemistry, and superintended large chemical works; he introduced into the processes improvements which he patented. He also designed and equipped chemical works in France, Australia, and the United States. For many years he was adviser and designer with Johnson, Matthey & Co.. Petrie died on 16 March 1908 at Bromley, Kent, and was buried there.
On the Results of an Extensive Series of Magnetic Investigations, including most of the known Varieties of Steel, communicated at the British Association's Southampton meeting of 1846; and papers presented to the Association in 1850;
Petrie married on 2 August 1851 Anne Flinders, only child of Matthew Flinders. She was a linguist, and studied Egyptology. Under the pseudonym "Philomathes" she published a work on the relation between mythology and scripture, and as "X.Q." contributed essays to periodical literature. Their only child was William Matthew Flinders Petrie the Egyptologist.