In return, Mr Ray will abandon charges arising from the Paula Jones sexual harassment case.
Mr Clinton said he "did not fully" tell the truth in talking about Ms Lewinsky in sworn testimony three years ago in the Jones case.
The BBC's Washington correspondent, Tom Carver, says it is unlikely that a prosecution would have succeeded, and the American public, weary of this scandal, would have seen it as an unnecessary persecution.
'Nation's interests'
Mr Clinton said, in a statement read by White House spokesman Jake Siewert: "I tried to walk a fine line between acting lawfully and testifying falsely.
"But I recognise that I did not I did not fully accomplish that goal, and that certain of my responses to questions about Ms Lewinsky were false.
"I hope my actions today will help bring closure and finality to these matters."
Mr Ray said: "The nation's interests have been served and therefore I decline prosecution.
"This matter is now concluded. May history and the American people judge that it has been concluded justly."
Mr Siewert said: "Hopefully this will give America the chance to put this particular episode behind them and then move on."
Perjury
The deal was worked out between Mr Ray and the president's private attorney, David Kendall.
It was Mr Clinton's testimony in the Paula Jones case, in which he denied sexual relations with Ms Lewinsky, that triggered the scandal which led to his impeachment by the House of Representatives in December 1998.
He was acquitted after a trial in the Senate in February 1999 allowing him to serve out his term.
But Mr Ray has been leading an investigation into whether Mr Clinton committed perjury, and was said to have been considering an indictment of him after he leaves office.
The deal effectively brings to an end the six-year Whitewater investigation that began with questions about the Clintons' Arkansas land deal but expanded to his conduct in the Oval Office.
After repeatedly denying an inappropriate relationship with Ms Lewinsky, the president finally acknowledged the affair in a televised speech, before becoming only the second president in US history to be impeached.