David McCallum, the Scottish-born actor who became a surprise sensation as the enigmatic Russian spy Illya Kuryakin on “The Man From U.N.C.L.E.” in the 1960s and found television stardom again almost 40 years later on the hit series “N.C.I.S.,” died on Monday in New York. He was 90.

“N.C.I.S.” announced his death in a post on X, the social media platform formerly known as Twitter. The announcement did not include any further information.

Trained at the Royal Academy of Dramatic Art in London, Mr. McCallum was an experienced character actor who could use an accent or an odd piece of clothing to give depth to a role. He played a wide range of parts across theater, film and television, from Shakespeare’s Julius Caesar in Central Park in 2000 to the voice of Professor Paradox on the animated television series “Ben 10: Ultimate Alien,” a decade later.

He was hired in 1964 to play Illya Kuryakin, the Russian-accented sidekick of Robert Vaughn’s Napoleon Solo, on “The Man From U.N.C.L.E.,” a tongue-in-cheek series about secret agents working for the fictional United Network Command for Law and Enforcement. His part was meant to be small; he had just four lines in the first episode. He suggested that Illya be made more interesting by having him be closemouthed about his personal life (“Nobody knows what Illya Kuryakin does when he goes home at night,” he told one interviewer) and somewhat antagonistic to Solo.

The writers began to build up his character, and he became a fixture of the series and a two-time Emmy Award nominee. Somewhat to his annoyance, he also became a sex symbol.

With his mysterious air, his Beatle haircut and his trademark black turtleneck, Mr. McCallum was a magnet for teenage fans. Sent on a publicity junket for the show to Louisiana State University at Baton Rouge in 1965, he was mobbed by screaming female students and had to be rescued by police officers.

“McCallum’s motorcades are now, by order of the police chiefs of the cities he visits, forbidden to stop anywhere along the line of drive,” The New York Times reported in a 1965 profile. “If the entourage slowed, there would be carnage in the streets.”

“The Man From U.N.C.L.E.” ended in 1968, and Mr. McCallum retreated happily to lower-profile roles. He continued to work steadily, mostly in B-movies and in supporting parts on television. He also played the title role in the short-lived series “The Invisible Man” (1975-76) and Emperor Joseph II in a revival of “Amadeus” on Broadway in 1999.

But everywhere he went, he said, the Russian secret agent stalked him. “It’s been 30 years, but I can’t escape him,” he told The Times in 1998. “Illya Kuryakin is there 24 hours a day.”

In 2003, the Russian shadow finally met his match in the bow-tied, bespectacled and eccentric medical examiner Donald Mallard, better known as Ducky, on the hit CBS crime series “N.C.I.S.” He remained with the show, which consistently ranked in the Nielsen Top 10, for two decades. He was still a member of the cast at his death.

In interviews, Mr. McCallum said that besides Julius Caesar, Dr. Mallard was his favorite role, in part because it taught him so much about forensics. He studied with pathologists in Los Angeles and even sat in on autopsies, learning enough that the show’s writers would ask him for technical advice.

David Keith McCallum Jr. was born on Sept. 19, 1933, into a musical family in Glasgow. His father was the first violinist for the Royal Philharmonic Orchestra in London; his mother, Dorothy Dorman, was a cellist. He would later tell interviewers that his Scotch Presbyterian upbringing had left him emotionally circumscribed.

“We Scots, we tend to be awfully tight inside,” he told TV Guide in 1965. “It has hurt me as an actor to be so — so naturally restricted.”

Expected to follow in the family footsteps and pursue a career in music, he enrolled in the Royal Academy of Music to study oboe. But he found himself drawn to acting and switched to the Royal Academy of Dramatic Art. (He never completely lost interest in music, however; at the height of his “U.N.C.L.E.” fame, Capitol Records released several albums under his name, on which he conducted instrumental renditions of pop hits.)

Mr. McCallum was drafted into the British military in 1951 and served two years, including 10 months in what is now Ghana as a small-arms expert. Not long after his discharge, he signed with the Rank Organization, a British production company, and began acting both in movies and on television.

He met Jill Ireland, already a rising actress in Britain, when they were both cast in the Rank production “Robbery Under Arms” in 1957. He proposed seven days after they met, and they married that spring. In 1961, when he was cast as Judas Iscariot in “The Greatest Story Ever Told” (the movie would not be completed and released until 1965), the couple moved to Los Angeles.

They appeared to flourish. They had three children. She became a busy TV actress and made several guest appearances on “The Man From U.N.C.L.E.,” playing three different characters.

But the strain of Mr. McCallum’s stardom took a toll on their marriage, and she left him for the actor Charles Bronson, whom she had met when Mr. McCallum and Mr. Bronson were both filming “The Great Escape” (1963). Less than a year after their divorce in 1967, Mr. McCallum married Katherine Carpenter, a model.

She survives him. Further information about his survivors was not immediately available. Mr. McCallum and his wife lived in Manhattan. The Associated Press said that CBS said he died at a Manhattan hospital but did not explain why he had been hospitalized.

When “N.C.I.S.” made Mr. McCallum a television star for the second time, he found fame much less oppressive than he had the first time. “In New York now I leave 15 minutes — because I walk everywhere in New York — between appointments because I am going to be stopped on the street to talk about N.C.I.S. for at least 15 minutes,” he told BBC Radio in a 2009 interview.

“I love it,” he said, when asked if he ever grew tired of that kind of attention. “I’ve never got fed up with anything in my whole life.”