President Trump took to Twitter on Wednesday to criticize his predecessors for failing to improve relations with Moscow.

WASHINGTON — President Trump defended on Wednesday his decision to disregard the advice of his national security team and congratulate President Vladimir V. Putin of Russia on his re-election, lashing out at the news media for reporting on how he diverged from his script and attacking his predecessors for failing to improve relations with Moscow.

Mr. Trump, enraged after officials leaked the contents of confidential notes he was given for the private phone call on Tuesday that exhorted him “DO NOT CONGRATULATE” Mr. Putin, argued in a pair of tweets on Wednesday afternoon that the conversation was part of his effort to foster better relations with Russia. He said such engagement could help the United States confront a host of national security challenges.

“I called President Putin of Russia to congratulate him on his election victory (in past, Obama called him also),” Mr. Trump wrote on Twitter, referring to President Barack Obama’s call to Mr. Putin in 2012. “The Fake News Media is crazed because they wanted me to excoriate him. They are wrong!”

But Mr. Trump’s handling of the call and his defense of it also pointed up his aversion to confronting Mr. Putin about Moscow’s misdeeds, which has become a theme of his presidency even as a special counsel investigates Russia’s efforts to sway the 2016 election in his favor.

Mr. Trump’s own advisers had warned him against congratulating Mr. Putin and, in briefing cards prepared before the call, told him to raise Moscow’s role in a nerve agent attack on a former Russian spy and his daughter living in Britain, an instruction he also ignored. The Washington Post first reported on the briefing cards, a leak that stunned some senior officials at the White House, where aides said on Wednesday that John F. Kelly, the chief of staff, had been deeply disappointed and frustrated by the disclosure.

One senior White…