Harvard is grudgingly giving up nearly $9 million in coronavirus relief after President Trump called out the elite university over federal aid awarded to schools as others are fighting for their economic lives.

The university announced Wednesday afternoon the school “has decided not to seek or accept the funds allocated to it by statute” as part of the nation’s Higher Education Emergency Relief Fund.

Both Stanford and Princeton universities have already rejected the bailout, saying smaller colleges desperately need it more.

Harvard’s decision to walk away from the money comes a day after Trump lambasted the Cambridge university for even considering the stipend — especially with the school sitting on a $40 billion endowment.

“Harvard’s going to pay back the money,” Trump said Tuesday at the daily coronavirus task force press conference. “They shouldn’t be taking it. … When I saw Harvard, they have one of the largest endowments anywhere in the country, maybe in the world, I guess. And they’re going to pay back that money.

“Harvard should pay that money back,” Trump added. “I want Harvard to pay the money back, OK. And if they won’t do that, then we won’t do something else. … This is meant for workers. This isn’t meant for one of the richest institutions, far beyond schools, in the world.”

Harvard said in a statement sent to the Herald Wednesday they are rejecting the cash infusion after pressure built around the payout.

“We have previously said that Harvard, like other institutions, will face significant financial challenges due to the pandemic and economic crisis it has caused,” the school said.

“We are also concerned however, that the intense focus by politicians and others on Harvard in connection with this program may undermine participation in a relief effort that Congress created and the President signed into law for the purpose of helping students and institutions whose financial challenges in the coming months may be most severe,” the statement adds.

Harvard said it will inform federal education officials of its decision “immediately,” adding that it hopes “special consideration” will be given less-affluent Massachusetts institutions “struggling” to survive and help students.

Earlier in the day a Harvard spokesman ripped into Trump for calling out the university over the funds and urged the Herald to study how endowments are used. The spokesman also questioned if other Boston-area colleges in line for the relief will do, calling out Northeastern, MIT and UMass Boston.

But Wednesday evening, Trump thanked Harvard and Stanford for refusing the relief money.

“I want to thank Harvard and Stanford and other companies,” Trump said. “I’m pleased to announce they won’t be taking the money.”