WASHINGTON — President Trump on Tuesday ousted his secretary of state, Rex W. Tillerson, extending a shake-up of his administration, 14 months into his tumultuous presidency, and potentially transforming the nation’s economic and foreign policy.

Mr. Trump announced he would replace Mr. Tillerson with Mike Pompeo, the C.I.A. director and former Tea Party congressman, who forged a close relationship with the president and is viewed as being more in sync with Mr. Trump’s America First credo.

Mr. Tillerson learned he had been fired on Tuesday morning when a top aide showed him a tweet from Mr. Trump announcing the change, according to a senior State Department official. But he had gotten an oblique warning of what was coming the previous Friday from the White House chief of staff, John F. Kelly, who called to tell him to cut short a trip to Africa and advised him “you may get a tweet.”

It was an abrupt end — after months of speculation — to a rocky tenure for a former oil executive who never meshed with the president who hired him. Mr. Tillerson clashed repeatedly with the White House staff and broke publicly with Mr. Trump on issues ranging from the dispute between Saudi Arabia and Qatar to the American response to Russia’s cyber aggression.

Mike Pompeo, Director of the CIA, will become our new Secretary of State. He will do a fantastic job! Thank you to Rex Tillerson for his service! Gina Haspel will become the new Director of the CIA, and the first woman so chosen. Congratulations to all!

At the State Department Tuesday afternoon, Mr. Tillerson said the president had called him from Air Force One just after noon — more than three hours after Mr. Trump had tweeted the news of his firing to his 49 million followers — to inform him personally of the dismissal. Mr. Tillerson said he planned to immediately step aside from his post, turning over all responsibilities by the end of the day to John J. Sullivan, the deputy secretary of state.

During a short statement in a briefing room packed with reporters, Mr. Tillerson said he would end his service at midnight on March 31, but was encouraging his policy planning team and under secretaries and assistant secretaries “to remain in their posts and continue in our mission at the State Department.”

“I’ll now return to private life, as a private citizen, as a proud American, proud of the opportunity I had to serve my country,” Mr. Tillerson said. He took no questions and left the briefing room.

The firing of Mr. Tillerson caught even the White House staff by surprise. Just the day before, a White House spokesman berated a reporter for suggesting there was any kind of split between Mr. Tillerson and the White House because of disparate comments on Russian responsibility for a poison attack in Britain.

But a senior administration official said that Mr. Trump decided to replace Mr. Tillerson now to have a new team in place before upcoming talks with Kim Jong-un, the North Korean leader he plans to meet by May. The president also wanted a new chief diplomat for various ongoing trade negotiations.

The White House’s purge extended to Mr. Tillerson’s inner circle. The under secretary of state for public affairs, Steve Goldstein, was fired, and the status was unclear of Mr. Tillerson’s chief of staff, Margaret Peterlin, and his deputy chief of staff, Christine Ciccone.

Mr. Tillerson was at the State Department on Tuesday and spoke to reporters, saying that he would surrender his authority at midnight and resign officially at the end of the month.

At the C.I.A., Mr. Pompeo will be replaced by the current deputy director, Gina Haspel, who will be the first woman to head the spy agency. Both she and Mr. Pompeo would need confirmation by the Senate to take the positions.

Mr. Tillerson has been out of favor with Mr. Trump for months but had resisted being pushed out. His distance from Mr. Trump’s inner circle was clear last week when the president accepted an invitation to meet with Mr. Kim, to Mr. Tillerson’s surprise.

Mr. Trump said Mr. Pompeo “has earned the praise of members in both parties by strengthening our intelligence gathering, modernizing our defensive and offensive capabilities, and building close ties with our friends and allies in the international intelligence community.”

“I have gotten to know Mike very well over the past 14 months, and I am confident he is the right person for the job at this critical juncture,” the president continued, in a written statement distributed by the White House. “He will continue our program of restoring America’s standing in the world, strengthening our alliances, confronting our adversaries, and seeking the denuclearization of the Korean Peninsula.”

In a Twitter post, Representative Nancy Pelosi of California, the House Democratic leader, warned that the turnover at the top of the State Department had diminished the United States with foreign leaders.

Whenever Secretary Tillerson’s successor goes into meetings with foreign leaders, his credibility will be diminished as someone who could be here today and gone tomorrow. https://t.co/DdyLCbpUiG

Mr. Pompeo, a former congressman, has become a favorite of Mr. Trump’s, impressing the president with his engaging approach during morning intelligence briefings. But he also, at times, has been at odds with the president — including agreeing with a C.I.A. assessment about Russia’s interference in the 2016 elections.

In picking Ms. Haspel to succeed Mr. Pompeo at the C.I.A., Mr. Trump opted for continuity rather than bringing in an outsider. At one point last fall, Senator Tom Cotton of Arkansas, one of the president’s closest Republican allies on Capitol Hill, had been tentatively tapped as the front-runner to run the agency if Mr. Pompeo moved up, but the idea later faded.

Mr. Tillerson, a former chief executive of the oil giant Exxon Mobil, had once been viewed as an intriguing, if unorthodox, cabinet choice. He had deep experience with Middle Eastern potentates, and knew President Vladimir V. Putin of Russia through Exxon’s extensive efforts to explore for oil in Russia.

An error has occurred. Please try again later.

You are already subscribed to this email.

But the early enthusiasm for bringing a business sensibility to the State Department faded fast, as Mr. Tillerson seemed overwhelmed by the diplomatic challenges before him and isolated by career foreign service officers whom he often froze out of the most important debates.

His profound disagreements with the president on policy appeared to be his undoing: Mr. Tillerson wanted to remain part of the Paris climate accord; Mr. Trump decided to leave it. Mr. Tillerson supported the continuation of the Iran nuclear deal; Mr. Trump loathed the deal as “an embarrassment to the United States.” And Mr. Tillerson believed in dialogue to resolve the North Korean nuclear crisis, but Mr. Trump repeatedly threatened military options.

Veteran diplomats said they could not remember a time when a president so regularly undermined his secretary of state so brazenly in the midst of a tense situation. Richard N. Haass, the president of the Council on Foreign Relations, who served many Republican presidents, last fall urged Mr. Tillerson to quit.

“Rex Tillerson has been dealt a bad hand by the Potus & has played it badly,” Mr. Haass wrote in a post on Twitter, using the acronym for president of the United States. “For both reasons he cannot be effective SecState & should resign.”

Career diplomats, who had seen in the gravelly voiced Mr. Tillerson a man of stature, experience and great wealth whom they hoped the president would respect and heed, eventually turned against him as he expressed more interest in shrinking the department than expanding American influence.

While other cabinet officers made their goals plain, Mr. Tillerson never set clear diplomatic priorities other than to pursue Mr. Trump’s slogan of “America First,” a term he never really defined. In an odd admission more than eight months into the job, Mr. Tillerson told employees in September that his top priority was to make the State Department more efficient. Yet he never fully addressed what diplomats should be doing with that greater efficiency.

Congress rebelled, declining to endorse his suggested 30 percent cuts in the State Department’s budget. But the message of his tenure seemed clear: At a moment when money was being poured into the Pentagon and intelligence agencies, diplomacy seemed less valued than at any time in recent American history.

The turning point for Mr. Tillerson came when NBC News reported that he had called the president a “moron,” leading him to take the extraordinary step of holding a news conference to affirm his support for Mr. Trump and insist that he had never considered resigning.

During a trip to Beijing in September, Mr. Tillerson told reporters that he already had “a couple, three” lines into North Korea to get communication started with the United States. Mr. Trump erupted the next morning, and denigrated the effort on Twitter by saying Mr. Tillerson was “wasting his time trying to negotiate with Little Rocket Man.”

“Save your energy Rex,” he added, “we’ll do what has to be done!” Mr. Trump later said he wished his secretary of state were tougher. The Chinese were left to wonder why Mr. Trump sent an emissary whose message the president did not believe in.

Part of the reason for Mr. Trump’s eruption then was that Mr. Tillerson’s suggestion of secret talks with North Korea surprised President Moon Jae-in of South Korea, who called the White House to complain, according to people with knowledge of the exchange. That Mr. Tillerson failed to take into account Seoul’s possible reaction was one of several embarrassing stumbles, arising from his own inexperience and decision to insulate himself from the department’s diplomatic corps.

With his ousting, Mr. Tillerson joins a long list of Trump administration appointees who have left or been fired, including the president’s first national security adviser, chief of staff, chief strategist, press secretary, two White House communications directors and secretary of health and human services.

Mr. Tillerson had some successes, including the growing international isolation of North Korea and improved ties between Saudi Arabia and Iraq. But he is likely to go down as among the least successful secretaries of state in history, and one big reason was his poor management of his relationship with Mr. Trump.

Although Mr. Tillerson spent his first months on the job getting to know Mr. Trump at lunches, dinners and White House get-togethers, the two never established a comfortable rapport.

The growing distance between the men was on clear display during Mr. Trump’s trip to Asia in November, when Mr. Tillerson visited the prison that once housed Senator John McCain, a Republican from Arizona who is a frequent critic of the president.

But perhaps the most puzzling part of Mr. Tillerson’s tenure was his poor oversight of the State Department. As a former top business executive, his managerial skills were thought to be his chief asset.

He approved one global conclave in Washington just eight days before the event was to start, ensuring that few leaders from around the world were able to attend. He rarely sat for comprehensive briefings with many of his top diplomats and often failed to consult the State Department’s experts on countries before visiting.

Foreign diplomats — starting with the British and the French — said Mr. Tillerson neither returned phone calls nor, with much advance warning, set up meetings with his counterparts. Strategic dialogues with many nations, including nuclear weapons powers like Pakistan, were ended without explanation.

Mr. Tillerson became so isolated that even top administration officials like Mr. Pompeo and allies like Condoleezza Rice, the former secretary of state whose recommendation was crucial to his selection, had trouble penetrating a phalanx of staff to speak to him directly.

“The relationship between top management and the bulk of the State Department was toxic,” said Ambassador James F. Jeffrey, a former senior diplomat and fellow at the Washington Institute who once worked with Mr. Tillerson. “And that was a total mystery because the people at the State Department would work for the devil if he is advancing American interests, which Mr. Tillerson was.”