WASHINGTON — The Senate in the early hours of Friday morning rejected a new, scaled-down Republican plan to repeal parts of the Affordable Care Act, derailing the Republicans’ seven-year campaign to dismantle President Barack Obama’s signature health care law and dealing a huge political setback to President Trump.

Senator John McCain of Arizona, who just this week returned to the Senate after receiving a diagnosis of brain cancer, cast the decisive vote to defeat the proposal, joining two other Republicans, Susan Collins of Maine and Lisa Murkowski of Alaska, in opposing it.

The 49-to-51 vote was also a humiliating setback for the Senate majority leader, Mitch McConnell of Kentucky, who has nurtured his reputation as a master tactician and spent the last three months trying to devise a repeal bill that could win support from members of his caucus.