Williams said he grew up listening to Gaye's music and was familiar with his song "Got to Give It Up," but did not use it as a basis for "Blurred Lines," which was a hit for him and collaborators Robin Thicke and T.I.
"He's one of the ones we look up to," Williams said. "This is the last place I want to be."
Williams, Thicke and T.I. are being sued by Gaye's children who claim "Blurred Lines" infringes their father's copyrights for 1977's "Got to Give It Up," but Williams' testimony is crucial because he wrote the song's music and most of its lyrics. Although Thicke received a songwriting credit on the song, he acknowledged earlier in the trial that he didn't do much work on the song.
T.I.'s rap track was added later, and Williams said he wasn't involved in its inclusion in "Blurred Lines," which was nominated for a Grammy Award. T.I., whose real name is Clifford Harris, is expected to be among the case's final witnesses on Thursday.
Williams spent more than an hour describing his musical process and he how he crafted "Blurred Lines" in mid-2012 in between working on tracks with Miley Cyrus and rapper Earl Sweatshirt. Thicke arrived after the music and lyrics had been written, Williams recalled. He quickly brought the singer up to speed and they began recording what would become 2013's biggest hit song.
"We were bopping and dancing," Williams recalled. "It was a cool night."
His answers were sometimes too lengthy for U.S. District Judge John A. Kronstadt, who cut off Williams several times mid-sentence and didn't allow him to elaborate on some of his answers.
"Blurred Lines" has earned more than $16 million in profits and more than $5 million apiece for Thicke and Williams, according to testimony offered earlier in the trial.
Williams said after the song was released, he saw similarities between "Blurred Lines" and Gaye's work but said that wasn't a conscious part of his creative process.
Richard S. Busch, who represents the Gaye family, asked Williams whether he felt "Blurred Lines" captured the feel of the era in which Gaye recorded.
"Feel," Williams responded. "Not infringed."
The case opened last week and featured testimony from Thicke, who told jurors that he took a songwriting credit on "Blurred Lines" despite Pharrell doing most of the work.
Thicke brought a bit of showmanship to a trial that has focused on minute details of chords and sheet music. He performed elements of "Blurred Lines" and hits by U2 and The Beatles to show how different songs can include similar-sounding musical elements.
Williams did not perform any music during his more than hour of testimony, and complained that audio comparisons of "Blurred Lines" and "Got to Give It Up" had been created in a way that made them sound similar.
Despite the lack of vocals on the tracks, Thicke bobbed his head while his hit was played.
The trial has included detailed analysis of snippets of chords and notes from both songs, all created in the same key. While jurors have heard "Blurred Lines," Kronstadt has ruled that they cannot hear Gaye's song in its entirety and "Got to Give It Up" can only be played as it appears in a sheet music submitted to get the song copyright protection.
Williams' career as an artist-producer has been booming in recent years, with the singer performing his hit "Happy" at the 2014 Oscars just weeks after winning three Grammy Awards for his work with Daft Punk.
He also serves as a judge on the NBC competition show "The Voice."
Anthony McCartney can be reached at http://twitter.com/mccartneyAPSuggest a correction