WASHINGTON — When President Donald Trump spoke to Marines at the Miramar Air Station in San Diego March 13, he threw out an idea that he suggested had just come to him.

"You know, I was saying it the other day, because we're doing a tremendous amount of work in space — I said maybe we need a new force. We'll call it the 'space force,'" he said. "And I was not really serious. And then I said what a great idea — maybe we'll have to do that."

The origin of the space force wasn't that simple.

The concept had been pushed unsuccessfully since 2016 by a small group of current and former government officials — some with deep financial ties to the aerospace industry — who see creation of the sixth military service as a surefire way to increase Pentagon spending on satellite and other space systems.

The idea of a space force "is not a new thing," said Stuart O. Witt, an aerospace executive and a member of White House's National Space Council Users Advisory Group. "The president just acted upon it."

But Rep. Jim Cooper, (D-Tenn., one of the early supporters of a separate service, complained that Trump's impromptu endorsement had "hijacked" the issue and could vastly inflate the budget process. "There are many vendors of all types who are excited at the prospect of an explosion of new spending, which was not our goal," he said.

Still, when Trump embraced the idea at Miramar — and began promoting it at other rallies — a moribund notion opposed by much of the Pentagon hierarchy and senior members of the Senate became a real possibility.

A few days after the San Diego speech, Trump took a phone call at his Mar-a-Lago resort in Florida from Rep. Mike D. Rogers, R-Ala., who is chairman of the House Armed Services subcommittee on strategic forces. He had been promoting the space force to Trump and his advisers for months.

"This is something we have to do," Rogers said he told Trump. "It's a national security imperative."

"I'm all in," Trump replied, Rogers said. "We are going to have a space force."

The story of how that happened is a window into the chaotic way Trump sometimes makes decisions, often by bypassing traditional bureaucracy to tout ideas that work well as applause lines but aren't fully thought out.

Only Congress can create a new military service, and the administration still has not said what the space force would do, what it would look like or what it would cost. The existing services — the Army, Navy, Air Force, Marine Corps and Coast Guard — not only deploy forces. They also run war colleges, recruiting stations, security and vast contracting operations, with costs in the billions of dollars.

Vice President Mike Pence said this month that the administration would send a legislative proposal to Capitol Hill next year and aims to establish a space force by 2020.

Congress has shown little appetite for a costly new expansion of government, especially one that would cut the Air Force budget, a service with powerful backing on Capitol Hill.

Those political headwinds could reduce the space force to a presidential rallying cry, like his unfulfilled vow to build a "big, beautiful wall" on the border with Mexico. But Trump's enthusiasm has clearly provided momentum, exciting proponents who see a rare opportunity to win more attention and resources for space defense.

They agreed on the threat. China and Russia were building weapons and cyber capabilities aimed at knocking out satellites that the Pentagon relies on for communication, precise targeting of bombs and missile defense, according to U.S. intelligence.

Last summer, Rogers and Cooper inserted an amendment in the annual defense policy bill to create a separate service they called the space corps. It would be part of the Air Force, just as the Marine Corps is technically part of the Navy.

But Rogers worried that putting it in the Air Force might not fly. The Air Force is dominated by flyers more interested in warplanes than in outer space, he noted in a speech last year, explaining Air Force opposition to a separate service.

"I mean, this is about money," Rogers said. "As long as space is in the (Air Force) portfolio, they can move money from space to support fighter jets, bombers or whatever. The Air Force is run by fighter pilots. Space will always lose."

Moreover, defense contractors involved in space "were complaining to us about how impossible it was to deal with the Air Force," Rogers said. "They kept describing this bureaucratic morass in Air Force procurement, where nobody had decision-making authority."

Rogers, who was first elected to Congress by a narrow thin margin in 2002, has solidified control of his rural district, with a campaign fund that has received considerable contributions from the aerospace industry. Defense industry companies have contributed $395,000 to his campaign committee and leadership PAC since 2017, becoming by far his largest industry donor, according to Open Secrets, a campaign spending database.

Also pushing for the space corps was Douglas L. Loverro, a retired Air Force officer and the former executive director of its Space and Missile Systems Center in El Segundo, Calif. Loverro said in an interview that a dedicated corps of space experts would be necessary to ensure that a space force could fulfill its mission.

The Air Force focus on conventional air combat prevents it from "building the best space war fighters — the ones who can conceive of, imagine, prepare for, and think doctrinally, operationally and technically about space," Loverro said at an industry conference in April. "But those are precisely the people we need today."

The space corps never got off the ground.

The Air Force lobbied to kill it. Defense Secretary James Mattis took the unusual step of sending a letter to Congress voicing his objections.

"At a time when we are trying to integrate the Department's joint warfighting functions, I do not wish to add a separate service that would likely present a narrower and even parochial approach to space operations," Mattis wrote.

Even the Trump White House called the idea "premature at this time" in a July 2017 statement.

That was enough to kill the plan in the Senate, though Rogers got other lawmakers to agree to order the Pentagon to study the idea and report on its findings.

He also began trying to enlist Trump.

Last December, Rogers said, he arranged for an intermediary to give Trump information his subcommittee had collected about Russian and Chinese development of anti-satellite weapons, and about the Air Force effort to kill a separate military service. He declined to identify the intermediary.

"With the Air Force having poisoned the well, I knew I needed to get some energy back in it," he said. "I knew once I got the word to him about what we'd found, I was certain he'd embrace it."

Trump seldom talked about space flight during the 2016 presidential campaign. When a 10-year-old boy asked him about space during a 2015 breakfast in New Hampshire, Trump said fixing roads was a higher priority.

"In the old days, it was great," Trump told the boy. "Right now we have bigger problems. You understand that, we've got to fix our potholes."

Once elected, Trump revived the space council, an advisory panel led by Pence that had been dormant since the early 2000s. The vice president had attended three space shuttle launches while serving in Congress, and was deeply interested in space.

When Pence gave an update during a Cabinet meeting in March, Trump marveled at model rocket ships displayed on the table in front of him. He touted the private space launch companies owned by billionaire businessmen, including Amazon's Jeff Bezos, Tesla's Elon Musk and Microsoft founder Paul Allen.

"We're letting them use the Kennedy Space Center for a fee," Trump said. "And you know, rich guys, they love rocket ships, and that's good. That's better than us paying for it."

But Trump showed no interest publicly in a space force until his speech in San Diego in March, indicating that it was his idea. By then, the Pentagon's attitude was beginning to shift. A Trump appointee, Deputy Defense Secretary Patrick Shanahan, had begun preparing the report ordered by Congress on whether to create an independent space force.

A former senior Boeing executive, Shanahan was familiar with the cumbersome Air Force procurement system. He became the administration's space force point person, consulting with Pence, Rogers, the Air Force and other Pentagon players, and the space council.

"I can hear my dad kind of whispering in my ear, 'Don't screw anything up,'" Shanahan said Aug. 9. "There are extensive military operations going on throughout the world right now and they're heavily reliant on space."

Trump began talking up a space force privately, telling Pence to take on the project, according to an administration official who confirmed reporting first published in Axios.

The aerospace industry, which was initially cool to the plan, began to come around, seeing a space force as a lucrative avenue not just for expensive new space systems, but also for uniforms, construction projects, support services and other needs of a new military service.