Donnie Darko star Gyllenhaal, 41, starred alongside Pitt’s then-wife, Friends star Jennifer Aniston, in 2002’s The Good Girl.
The film, which also featured John C Reilly, saw Aniston receive plaudits for the role in which her character has an affair with a colleague, played by Gyllenhaal.
Speaking to W Magazine, he said: “I was starstruck with Mandy Patinkin when he came to see Sunday In The Park With George, a show I did. He originated the (title) role and basically created the role.
“And I was definitely starstruck when I first met Brad Pitt on the set of The Good Girl.
“I was working with Jennifer Aniston, who was his wife at the time, and there were a lot of very racy scenes.
“I remember putting my hand out to shake his, and accidentally hitting the door.
“He said, so confidently and kindly, “Well, you have another one. It’s all right’.
“He was very, very, very sweet to me, and it was actually a really lovely exchange.”
Aniston and Pitt began dating in 1998 and were married in 2000, but divorced in 2005.
Brokeback Mountain star Gyllenhaal also spoke about his favourite films growing up, telling the publication they were Gigi and Point Break.
He said: “I was forced to watch Gigi, and so it slowly became my favourite film.
“But then it was Point Break. Doesn’t that sort of encapsulate me?”.