WASHINGTON — The Senate Judiciary Committee fired a political warning shot at the White House on Thursday, advancing on a bipartisan vote long-stalled legislation to allow special counsels such as Robert S. Mueller III to appeal their firing to a panel of judges and possibly be reinstated.

Senator Mitch McConnell of Kentucky, the majority leader, has stated unequivocally that he will not bring the bill to the Senate floor for a vote. But with four Republicans, including the committee’s chairman, Senator Charles E. Grassley of Iowa, joining Democrats to vote in favor of it, the measure sent a clear message to President Trump that there would be serious consequences to firing the special counsel.

Even senators who voted against the legislation warned Mr. Trump against trying to dismiss Mr. Mueller. Senator Orrin G. Hatch of Utah, the longest-serving Senate Republican, said that “firing Mueller would cause a firestorm and bring the administration’s agenda to a halt. It could even result in impeachment.”

Mr. Trump seemingly offered fresh reason for their concern earlier on Thursday. In a telephone interview with “Fox & Friends,” he again aired his frustration with the Justice Department and with Mr. Mueller’s team, which he dismissed as being filled with partisan Democrats. He said he had been trying not to interfere in matters before the Justice Department.