Born in Beaufort, South Carolina, Grayson pursued classical studies and graduated from South Carolina College at Columbia in 1809, where he was a member of the Clariosophic Society. He then studied law and was admitted to the bar in 1822. He became a practicing lawyer in Beaufort, South Carolina.
He served as a member of the State House of Representatives from 1813 to 1815 and 1822 to 1825 and in the State Senate from 1826 to 1831. Grayson was elected commissioner in equity for Beaufort District in 1831 and resigned from the senate.
He was elected as a Nullifier to the Twenty-third and Twenty-fourth Congresses (March 4, 1833 – March 3, 1837). He then served as collector of customs at Charleston from August 9, 1841, to March 19, 1853. After his term as collector of customs, he retired to his plantation. He was a frequent contributor to the Southern Quarterly Review.
The Oxford English Dictionary credits William J. Grayson with having first used the phrase "master race" in his poem "The Hireling and the Slave" (1855); the phrase denotes the relation between the white masters and black slaves:
For these great ends hath Heaven’s supreme command