Thomas Schlamme, an executive producer, also is leaving. The show will continue with John Wells, another executive producer, in charge. Wells' other series include NBC's "ER" and "Third Watch."
There have been reports of tension between Sorkin and the studio that produces the show, Warner Bros. Television, with Sorkin reportedly cautioned about budgets and production delays. But there was no mention of that from either side following Thursday's announcement.
"This has been the experience of any writer's dreams," said Sorkin, an executive producer who also penned most of the scripts for the series that stars Martin Sheen as fictional President Josiah Bartlet. "I had the best job in show business for four years and I'll never forget that."
He and Schlamme said in a statement that they will pursue other film, television and theater projects, while remaining "the two biggest fans of 'The West Wing.'"
Their work was lauded by the studio and NBC.
"Aaron Sorkin and Tommy Schlamme have done an extraordinary job in their four years at the helm of 'The West Wing,'" said NBC entertainment chief Jeff Zucker and Warner Bros. Television President Peter Roth.
"The West Wing" won its third consecutive best drama trophy at last year's Emmy Awards. Sorkin has won an Emmy for writing for the series, while Schlamme has won two Emmys for directing.
The drama, which last season was the 10th-ranked primetime program, has fallen in the ratings and is No. 23 as the current season nears its end. Competition from ABC's reality series "The Bachelor" and "The Bachelorette" helped siphon off viewers, especially younger ones favored by advertisers.
Sorkin, 41, went through difficult personal times during his work on the show. He was arrested in 2001 for investigation of possessing cocaine and hallucinogenic mushrooms and ordered to enter a drug treatment program. The charges were dismissed after he completed the program.