Actor Michael Urie (April Greer)

As an acting student at Juilliard in the early 2000s, Michael Urie was required to pick a play excerpt to perform in a Shakespeare scene-study class. His instinct was to go right for the really tough stuff: a scene from “Hamlet.”

“Jessica Chastain and I did the nunnery scene,” Urie recalled in an interview. “I remember my classmates saying, ‘You’re doing what?’ ” Chastain remembered it vividly, too.

“This scene was special,” the Oscar-nominated actress recounted in an email.  “Michael put love notes for Ophelia on the student board every other day leading up to our rehearsals. When I handed Hamlet back his love letters in the beginning of the scene, I used the ones that Michael had written.” Of the inventiveness Urie brought to the assignment, she added: “That’s how you know you’re working with a great actor.”

The class was taught by Michael Kahn, who seems to have thought pretty much the same thing. Because the Texas-born Urie, best known as a giddily mischievous underling on ABC’s “Ugly Betty,” is to play Hamlet for Artistic Director Kahn next winter at Shakespeare Theatre Company.

The casting, which was announced Thursday by the company, is noteworthy not only because of Kahn’s history with Urie, but also because this “Hamlet” undoubtedly constitutes the last version of Shakespeare’s emblematic tragedy that Kahn will stage for the company, from which he retires at the end of the 2018-2019 season after more than three decades at the helm. In prior productions, Tom Hulce and Jeffrey Carlson — the latter also a Juilliard graduate — played the Danish prince for Kahn in Washington.

“Over the years I enjoyed watching Michael develop his talents, along with his comedic and physical skills, which resulted in some extraordinary performances,” Kahn said. “Each time I saw him in a dramatic role, I wanted to cast him in ‘Hamlet,’ and this season has provided me with the opportunity to do that.”

Urie, who turns 37 next month, found early success a decade ago as “Ugly Betty’s” Marc St. James, personal assistant of Vanessa Williams’s conniving fashion magazine creative director Wilhemina Slater. Still, much of his résumé is filled with stage work, most notably, the 600 times he portrayed the sole character in Jonathan Tolins’s “Buyer and Cellar,” an imagined tale about an actor hired to work in a basement shop in Barbra Streisand’s Malibu compound. At present, he’s the star of a hit off-Broadway mounting of the Nikolai Gogol satire “The Government Inspector,” and in September, Urie takes on the role of Arnold in a major revival at Second Stage Theatre of Harvey Fierstein’s “Torch Song Trilogy,” now retitled “Torch Song,” with Moisés Kaufman directing and Mercedes Ruehl as his mother.

He’s had a soft spot for canonical roles ever since Juilliard, where he earned the John Houseman Prize, bestowed upon the best classical actor. “I see it anytime I can, because I love it,” Urie said of “Hamlet,” with which he’s had some other professional experience: He played Horatio to Hamish Linklater’s Hamlet a decade ago at South Coast Repertory in Orange County, Calif. “I can still hear every one of Hamish’s line readings.”

The opportunity to begin formulating his own line readings was presented to him by Kahn last fall after the artistic director saw him in an off-Broadway play. “Right in the lobby, he asked me,” Urie recalled. “I saw him in the hallway, and he said, ‘Want to do Hamlet?’ I said, ‘Of course I do!’ ” They agreed then and there. “It still hasn’t really sunk in,” Urie added.

Performances begin Jan. 16 in the company’s Sidney Harman Hall. One person eager for the results is Urie’s drama school scene partner. “I’m really excited that Michael Kahn and Urie are working on ‘Hamlet’ again,” Chastain said. “It’ll be so interesting to see how the performance has grown all these years later.”