Proponents in both parties said the move was long overdue.
“For far too long, the story of our country’s history has been incomplete, as we have failed to acknowledge, address and come to grips with our nation’s original sin of slavery,” said Senator Edward J. Markey, Democrat of Massachusetts and a lead sponsor of the bill.
Senator John Cornyn, Republican of Texas, who pushed for passage, said he had talked to Mr. Johnson “many times about his concerns.”
“I think he saw that this was inevitable,” Mr. Cornyn said.
Many states have recognized Juneteenth for decades, but only some observe it as an official holiday. The day is already celebrated in 47 states and the District of Columbia.
After the protests for racial justice last year, dozens of companies moved to give employees the day off for Juneteenth, and the push for federal recognition as a paid holiday gained new momentum.
Texas was the first state to observe Juneteenth as an official holiday, starting in 1980.
The push to recognition comes as Republicans around the country, including some in Congress, are pushing to bar schools from using curriculum that explores the legacy of slavery and teaches about the effects of racism on myriad aspects of society.
“We do know there’s a movement to erase history with attacks on critical race theory and teaching children about the presence of systemic racism in our country’s history,” Mr. Markey said.
Making Juneteenth a federal holiday “acknowledges slavery as the original sin built into the United States Constitution,” he added. “We celebrate its eradication, but we can’t celebrate how deeply racism resulted in America’s policies and is still built into education, health care, housing and every other policy.”