William D. Ruckelshaus, who resigned as deputy attorney general rather than carry out President Richard M. Nixon’s illegal order to fire the independent special Watergate prosecutor in the constitutional crisis of 1973 known as the “Saturday Night Massacre,” died on Wednesday at his home in Seattle. He was 87.

His death was confirmed by his daughter Mary Ruckelshaus.

A lawyer and political troubleshooter, Mr. Ruckelshaus twice headed the United States Environmental Protection Agency, as its founding administrator from 1970 to 1973 under Nixon, and from 1983 to 1985 under President Ronald Reagan. He won praise for laying the new agency’s foundations, and later for salvaging an E.P.A. that had strayed from its mission and lost the confidence of the public and Congress.

Mr. Ruckelshaus was a champion of America’s natural resources in his home state of Indiana; in Washington State, where he lived; and while serving on presidential commissions and conservation groups. But he also worked for big business, was not an environmentalist of the Greenpeace and Sierra Club stripe, and in 50 years of public and private service was hailed and vilified by partisans on both sides as he tried to balance economic and ecological interests.

For many Americans, however, the deeds of Mr. Ruckelshaus’s varied career were all but eclipsed by his role in the events of a single night in the autumn of 1973, as the political dirty tricks and cover-up conspiracies of the Watergate scandal closed in on his boss, the beleaguered President Nixon.