Born on September 26, 1842, in Waterford, Pennsylvania, McWilliams was still living in that city when he joined the Navy. He served as a landsman on the in the Wilmington Campaign, from the First Battle of Fort Fisher on December 24, 1864, through the campaign's end on February 22, 1865. He was severely wounded and received treatment at a hospital in Portsmouth, Virginia. For his actions during the campaign, he was awarded the Medal of Honor months later on June 22, 1865.