William Barrett was born on August 14, 1896, in Philadelphia, Pennsylvania, the son of Irish immigrants. He attended school at the Brown Preparatory School in Philadelphia before attending St. Joseph's College. He subsequently studied law at the South Jersey Law School in Camden, New Jersey. He then went into business in real estate and served on the Board of Mercantile Appraisers in Philadelphia, where he also served on the Democratic city committee.
Barrett was elected to the United States House of Representatives as a Democrat, where he served for two years in the 79th Congress from 1945 to 1947. He unsuccessfully sought a second term in the 1946 election. Two years later, Barrett was elected to his old seat in the U.S. House and was reelected thirteen times, serving from 1949 to his death on April 12, 1976 in Philadelphia. He was interred in Holy Cross Cemetery in Yeadon, Pennsylvania.