The full extent of the fusion in the personal and professional relationship between David Cameron and Rebekah Brooks, the former News International chief executive, was laid bare at the Leveson inquiry when it emerged she texted to say she was rooting for him as a personal friend and because professionally "we are definitely in this together".

The gushing text sent on the eve of his conference speech in 2009, and the frequency of his meetings with News International executives, caused acute discomfort to the prime minister, but he emerged from the day-long judicial inquisition with his chief lines of defence intact.

He admitted he was haunted by his decision to hire Andy Coulson, the former News of the World editor, as Conservative communications director. But he said he sought assurances on his involvement in phone hacking at his former newspapers

It also emerged the chancellor George Osborne congratulated the culture secretary Jeremy Hunt on his appointment to oversee News Corp's bid for BSkyB at least half an hour before the arrival of legal advice on the suitability of his appointment.

In the most uncomfortable and revelatory moments, Cameron stumbled as he was asked whether he saw Brooks every weekend in 2008 and 2009, before his wife Samantha told him in the lunchtime break that they had met every six weeks, or a bit more.

He was then confronted with Brooks's text, recently obtained by Leveson lawyers under the Inquiries Act from News International, in which she promised "I am so rooting for you tomorrow, not just as a personal friend but because professionally we're definitely in this together." The text refers to how they should have a "country supper soon", praises his Old Etonian allies and signs off with "Yes He Cam!".

No replies by text from Cameron are available since such texts are not collated centrally by No 10.

Cameron admitted he was in favour of market-led takeovers, but insisted there had been no overt, or covert deal to trade a go ahead for the bid in return for the support of News International newspapers prior to the 2010 election.

Cameron said Gordon Brown's claim that the Tories agreed to cut funding for the BBC and media regulator Ofcom in return for political support from News International was "complete nonsense" and had been made because he was "very angry and disappointed" at the Sun's decision to switch support from Labour before the 2010 general election.

Cameron also came under pressure over his role in appointing Hunt to oversee the BSkyB bid in December 2010, saying the business secretary Vince Cable had made it "literally impossible" to retain the job when it was revealed he had told under cover reporters he had declared war on News International. Speaking of Hunt's appointment on 21 December, Cameron said: "It was not some rushed, botched, political decision. If anyone had told me Jeremy Hunt couldn't do the job I wouldn't have given him the job."

But he admitted he did not show the cabinet secretary Lord O'Donnell a private memo sent in November by Hunt lobbying him to back the bid. He said he had forgotten about the memo, but conceded it should have been provided to the cabinet secretary. The memo had been a legitimate attempt to represent the views of a large media company, he said

But he crucially came to the inquiry armed with new advice from the Treasury solicitor Paul Jenkins in a witness statement asserting if he had seen the Hunt lobbying memo it would not have changed his view that Hunt was capable in the future of handling the quasi-judicial decision objectively.

It was disclosed that cabinet secretary Jeremy Heywood, proposed Hunt at a meeting starting a little before 5pm, and legal advice from the culture department giving the go-ahead for the appointment was not received in No 10 until 5.30pm.

Yet chancellor George Osborne texted the culture secretary at 4.58 pm to say he hoped he liked the solution of appointing him to oversee the bid more than 30 minutes before legal sanction was received. That sanction was given on the phone by Jenkins after he was read the gist of Hunt's previously published remarks in the FT supporting the bid. The announcement was made at 5.45 pm.

The BSkyB bid was eventually abandoned in July 2011 amid outrage over the phone-hacking scandal.

Cameron effectively conceded the bid had been mishandled by saying he would be seeking to rewrite parts of the ministerial code to cover quasi-judicial decisions. He also said special advisers needed better training and management and that something had gone wrong in the supervision of Hunt's special adviser Adam Smith.

The PM's witness statement reveals he had 1,404 meetings with "media figures" – 26 a month on average – while in opposition between 2005 and 2010. Once in government, that fell to about 13 a month. He said in future a note taker will be present if a media executive is going to raise commercial issues at meetings with him.

Cameron said the relationship between politicians and the media had deteriorated. "How we get it to a better place, I think part of it will be about transparency, better regulation, having a bit more distance. That will be part of respect."

His spokesman said any solution in terms of future regulation should be based on a cross-party consensus, and hinted it should be achieved by 2015. Cameron told the inquiry: "What's taken a long time to go wrong I suspect will take quite a long time to be put right"

Any new system of regulation had to include "independence, penalties, compulsion, toughness, public confidence and all the rest of it", he said.

He suggested one penalty might be to remove access to government information or the lobby system from any newspaper that does not comply with a universal regulatory system.

He stressed "it would be better to try everything before you reach the lever of statutory regulation" and said it is a forlorn hope to require newspapers to distinguish between comment and news.

On the BBC's Newsnight programme the Conservative party's deputy chairman Michael Fallon referring to the texts between Brooks and Cameron said: "If it is an embarrassment, it is an embarrassment to her and not to him". Tom Watson, the Labour deputy chair said he feared that Cameron's evidence suggested he is beginning to go cold on the idea of press reform.