Republican leaders of the House of Representatives pulled the legislation due to a shortage of votes despite desperate lobbying by the White House and its allies in Congress.
They had planned a vote on the measure after Trump cut off negotiations with Republicans who had balked at the plan and issued an ultimatum to vote on Friday, win or lose.
Republican moderates as well as the most conservative lawmakers had objected to the legislation. The White House and House leaders were unable to come up with a plan that satisfied both moderates and conservatives.
Trump told the Washington Post: "We just pulled it."
Amid a chaotic scramble for votes, House of Representatives Speaker Paul Ryan, who has championed the bill, met with Trump at the White House before the bill was pulled from the House floor after hours of debate. Ryan said he recommended that the legislation be withdrawn from the House floor because he did not have the votes to pass it, and that Trump agreed.
Friday's events cast doubt on whether Ryan can get major legislation approved by fractious Republican lawmakers.
"I will not sugarcoat this. This is a disappointing day for us," Ryan said at a news conference, adding that his fellow Republicans are experiencing what he called "growing pains" transitioning from an opposition party to a governing party.
"Doing big things is hard," Ryan added, noting that he got close but failed to muster the 216 votes needed to pass it.
Ryan said he did not know what the next steps would be on healthcare, but called Obamacare so flawed that it would be hard to prop up.
Trump told the Washington Post the healthcare bill would not be coming up again in the near future and that he wanted to see if Democrats who uniformly objected to the Republican plan would come to him to work on healthcare legislation, a Washington Post reporter said on MSNBC.
Without the bill's passage in Congress, Democratic former President Barack Obama's signature domestic policy achievement, the 2010 Affordable Care Act - known as Obamacare - would remain in place despite seven years of Republican promises to dismantle it.
Repealing and replacing Obamacare was a top campaign promise by Trump in the 2016 presidential election, as well as by most Republican candidates, "from dog-catcher on up," as White House spokesman Sean Spicer put it during a briefing on Friday.
The House failure to pass the measure called into question Trump's ability to get other key parts of his agenda, including tax cuts and a boost in infrastructure spending, through a Congress controlled by his own party.
News that the bill had been pulled before a final vote was greeted initially with a small sigh of relief by US equity investors, who earlier in the week had been fretful that an outright defeat would damage Trump's other priorities, such as tax cuts and infrastructure spending.
Benchmark US stock market indexes ended the session mixed after rallying back from session lows following the news. The S&P 500 Index ended fractionally lower, the blue chip Dow Jones Industrial Average slipped about 0.3 percent and the Nasdaq Composite Index rose about 0.2 percent.
The dollar also strengthened modestly on the news and US Treasury bond yields edged up from session lows.
"There's nobody that objectively can look at this effort and say the president didn't do every single thing he possibly could with this team to get every vote possible," Spicer told reporters before the legislation was pulled.
Trump already has been stymied by federal courts that blocked his executive actions barring entry into the United States of people from several Muslim-majority nations. Some Republicans worry a defeat on the healthcare legislation could cripple his presidency just two months after the wealthy New York real estate mogul took office.
In a blow to the bill's prospects, House Appropriations Committee Chairman Rodney Frelinghuysen announced his opposition, expressing concern about reductions in coverage under the Medicaid insurance program for the poor and the retraction of "essential" health benefits that insurers must cover.