The agreement with Ms. Mackris, the former producer on Mr. O'Reilly's program on Fox News who sued him in 2004, accusing him of sexual harassment, includes a previously unknown provision showing that her lawyers agreed to change sides to work for Mr. O'Reilly after the salacious dispute. It was settled for about $9 million, according to people familiar with the matter. The mediator for the dispute was the lawyer Marc E. Kasowitz, who went on to represent Mr. O'Reilly last year. (Mr. Kasowitz also has represented President Trump.) As part of the settlement, Ms. Mackris's former lawyers at the firm Benedict P. Morelli & Associates agreed to provide legal advice to Mr. O'Reilly on sexual harassment matters. They also agreed not to represent other parties with sexual harassment claims against Mr. O'Reilly or Fox News.