Gordon Brown wrote to media mogul Rupert Murdoch complaining about The Sun's attacks on the war in Afghanistan, the Leveson Inquiry has heard.
Documents given to the inquiry into press standards as part of Mr Murdoch's evidence include the letter, dated April 2010, from the Prime Minister to the tycoon.
Mr Brown wrote that he thought in a previous conversation Mr Murdoch had agreed the tabloid would stop attacking Government policy in Iraq and Afghanistan.
"Yet, almost every day in recent weeks, The Sun has chosen to accuse me personally of letting the Armed Forces down," he said.
Mr Brown said polls had shown two-thirds of the British public wanted troops out of Afghanistan, adding: "While The Sun says it wishes to persuade people we need more troops in Afghanistan, all they have succeeded in doing is persuading people that our troops should leave Afghanistan.
"Irrespective of such polls and the way The Sun behaves, I will stand firm for our policy against the Taliban," he wrote, adding that he planned to increase funding for the war from £750 million the year before he took over as Prime Minister to £5,000 million.
He added: "But it is unfair, to say the least, to find the newspaper that says it supports the campaign in Afghanistan undermining public support by the way it behaves.
"If this kind of newspaper editorialising continues (and of course that is your right) the public will come to a settled view that they do not want their troops fighting at all."
The Prime Minister, whose wife Sarah was known to have a close relationship with Mr Murdoch's wife Wendi, added: "My best wishes to Wendi, and to Chloe and Grace."
Yesterday Mr Murdoch told the inquiry Mr Brown rang him in an "unbalanced" state of mind, declaring "war" on his media empire when The Sun switched support to the Conservatives in September 2009.
But the former prime minister denied contacting the media tycoon about the daily tabloid's change of allegiance.
Last night he said the only phonecall he had with Mr Murdoch in his last year in office was in the second week of November 2009 after The Sun published a story accusing him of mis-spelling the name of a soldier killed in Afghanistan in a letter to his mother.
Bereaved mother Jacqui Janes, from Portslade, West Sussex, later accepted an apology from Mr Brown after he spoke about knowing how it felt to lose a child.
But today media mogul Mr Murdoch told the Leveson Inquiry he could not remember a conversation about that issue, though he thought the story was "cruel" at the time.
He said: "At the time I spoke to the editor and thought it was too hard on Mr Brown. He had taken the trouble to write to a mother, obviously in a hurry, his handwriting wasn't very good.
"But it seemed to be very cruel because he had taken the trouble.
"But I don't think I rang him personally to apologise or talk about it. I may have."