The compromise bill, written by Senators Thom Tillis of North Carolina and Lindsey Graham of South Carolina, both Republicans, and Chris Coons of Delaware and Cory Booker of New Jersey, both Democrats, would enact a statute codifying an existing Justice Department regulation that says a special counsel may be fired only by the attorney general, and only for good cause, like misconduct.

The bill also creates a 10-day window within which a special counsel can seek judicial review of the firing. If it is determined that the special counsel was not, in fact, fired for good cause, then he would be reinstated. In the interim, it would ensure that the special counsel’s staff and investigative materials are preserved.

Democrats, who have been clamoring for Congress to act to protect Mr. Mueller, touted the new legislation as a breakthrough but privately conceded that odds remained stacked against its passage. Mr. Tillis, in his own comments, sought to put distance between the measure and the bubbling tensions between Mr. Trump and Mr. Mueller’s investigation into Russia’s election interference and possible ties to the Trump campaign.

“This compromise bipartisan bill helps ensure that special counsels — present or future — have the independence they need to conduct fair and impartial investigations,” Mr. Tillis said. “The integrity and independence of special counsel investigations are vital to reaffirming the American people’s confidence in our nation’s rule of law.”

Mr. Grassley, who has raised concerns about the constitutionality of the bill, plans to offer an amendment to it that would formally require the Justice Department to produce reports to Congress each time there is a change in scope to a special counsel’s investigation or if he is fired. The department would also have to prepare a detailed final report about what a special counsel found and explain any decisions to charge or decline to charge particular suspects, according to Republican committee aides.