WASHINGTON — A federal judge on Friday ordered Hillary Clinton to provide written testimony under oath about why she set up a private computer server to send and receive emails while secretary of state, ensuring that the issue will continue to dog her presidential campaign until the eve of the election.

In a brief ruling issued on Friday afternoon, the judge, Emmet G. Sullivan of Federal District Court in Washington, approved a motion by the conservative advocacy organization Judicial Watch to pursue its vigorous campaign to expose Mrs. Clinton’s use of the private server. In addition to requiring her testimony in writing, the judge allowed the group to depose a senior State Department aide who had warned two subordinates not to question her email practices.

Only six weeks ago, the director of the F.B.I., James B. Comey Jr., declined to recommend prosecuting Mrs. Clinton, saying that while her actions had been careless, they did not amount to a crime. Yet the controversy refuses to dissipate. This week, the bureau turned over to Congress the documents it compiled in the case, including a three-and-a-half hour interview with Mrs. Clinton, even as Republicans in Congress pressed their public case for her to be charged with perjury.

Judge Sullivan’s ruling opened another front in a fight Mrs. Clinton’s campaign certainly hoped to put behind her. Although he declined to order her to answer questions in person, his ruling underscored the legal complications that Mrs. Clinton faces even as she enters the homestretch of her campaign.