White supremacists held a rally in Washington on Sunday, and almost no one but their opponents and the police showed up.

Jason Kessler, one of the organizers of last year’s violent and deadly “Unite the Right” rally in Charlottesville, wanted to hold an anniversary demonstration there, but the city wouldn’t let him. So he brought his show to Washington, where he hoped 400 supporters would join him for a rally at Lafayette Square, across from the White House. Fewer than 40 turned out.

The group was met by thousands of protesters who filled their half of the leafy, seven-acre park chanting “Go home, Nazis!” “No Trump! No KKK! No fascist USA!” and “Black lives matter!” They drowned out whatever message Kessler and his small band of followers had hoped to deliver — and that was their goal.

For opponents, the day felt like a victory, albeit an often tense and angry one.

Samaj Calhoun, a Southwest Washington resident, came to protest the rally with friends to show they wouldn’t be intimidated by the white supremacists. Calhoun said she hopes the rest of the country watching the District sees “that we’re not afraid. And we can defend our city.”

City leaders and law enforcement officials were determined that the event would not be a repeat of the mayhem in ­Charlottesville last year, when city police and Virginia state troopers allowed white supremacists and neo-Nazis to clash in the streets with anti-hate protesters. Counterprotester Heather Heyer was killed when a man police say identified himself as a Nazi drove a car into a crowd. Two state troopers died when their helicopter crashed following a day of monitoring the civil disturbance.

A massive police presence Sunday kept the two sides separated, and outside of a confrontation between some antifa, or ­anti-fascist, protesters and police long after the rally had ended, there were no reports of violence. Police reported that one man was arrested after he assaulted a man wearing a “Make America Great Again” hat.

D.C. Mayor Muriel E. Bowser (D) said last week the city would ensure that the rallygoers could exercise their right to free speech — even if what they were saying was distasteful.

“While we are opposed adamantly to what we are going to hear, we know what our responsibility is — to protect First Amendment events, to protect Washingtonians and to protect our city,” she said.

Bowser returned to the District Sunday afternoon from a trip to El Salvador to supervise the city’s response. She planned to return to El Salvador on Monday morning to finish the sister-city trip.

For law enforcement, getting Kessler and his followers to and from the event without incident proved the biggest — and most controversial — challenge.

Kessler and his supporters arrived a little before 1 p.m. at the Vienna Metro station, where they were accompanied by law enforcement officers onto the rear car of a waiting train. After the group disembarked at the Foggy Bottom Metro station, a larger police contingent, including officers on bicycles and motorcycles, escorted them on a walk of several blocks past protesters who shouted and chanted at them. Once inside Lafayette Square, protesters were kept far away from Kessler’s group.

Critics, including two D.C. Council members and the union representing Metro employees, lambasted the transit agency for providing the group extra protection after having said last week that its members would not be given special treatment.

“Giving white supremacists & hate groups a private Metro rail car is so unbelievably wrong & disgraceful. Beyond the horrible precedent it sets, what does it tell the riding public & operators? Plus, it’s the exact opposite of what @WMATA said they’d do,” council member Charles Allen (D-Ward 6) tweeted.

At Lafayette Square, protesters continued to yell and chant, and some, including a small contingent of antifa members dressed in black, hoped for a showdown with the white supremacists when the rally ended a little before 5 p.m. Police acted quickly to spirit Kessler and his followers out of the area in white vans to the Rosslyn Metro station, where they boarded a train to return to Vienna. Fairfax County Executive Bryan Hill said police were stationed along Interstate 66 to make sure no one tried to throw debris onto the train tracks or cause any other trouble.

Antifa members vented their frustration at not being able to confront the rallygoers by lighting smoke bombs and firecrackers and throwing eggs in the direction of police. By then, a steady rain was falling, however, and the protest was fizzling. Most began heading home, but police kept a watchful eye as the black-clad group carrying umbrellas wandered about knocking over trash cans, chanting “Bust a window!” and yelling at police to get out of their cars and “meet us in the streets.” A confrontation between the protesters and police erupted briefly near 13th and G streets NW.

While police were successful at keeping the opposing groups apart, the effort came at what is expected to be a significant expense to the city for overtime and deployment of law enforcement resources. District officials said late Sunday they were still tallying the cost of the rally to the city. At least some of it would be reimbursed by the federal government, they said, because Kess­ler’s event took place on National Park Service land.

At the rally, Kessler spent much of his 15-minute speech defending last year’s Unite the Right rally and insisting, despite evidence to the contrary, that most of those who attended had been nonviolent.

Earlier in the day, Kessler spoke to several reporters at the Vienna Metro station. He said he and his group were there to promote free speech and to protest “white civil rights abuses.”

When asked whether he had anything to say to Heather Heyer’s mother, Kessler offered his “condolences” but said police in Charlottesville should have blocked off the street where she was killed.

Several days after her death last year, Kessler tweeted, “Heather Heyer was a fat, disgusting Communist. Looks like it was payback time.”

Mikisa Thompson, who was on the front lines of the counter­protesters in Lafayette Square, said she traveled to Washington from North Carolina. She said she specifically came out for people who were traumatized and beaten last year in Charlottesville, notably Heyer.

“That’s why I’m here, for Heather,” she said.

Other protesters voiced different reasons for showing up Sunday.

At the Martin Luther King Jr. Memorial, about 20 protesters marched to the Lincoln Memorial while singing “We Shall Overcome.”

The group’s leader, Hawk Newsome, said Kessler had invited him and his group, Black Lives Matter of Greater New York, to attend this year’s Unite the Right rally.

“He thought that I was a friend, but I am not his Negro,” Newsome said. “I am not some token black you can use to validate yourself.”

BLM-GNY — which has been disavowed by the broader Black Lives Matter network — went viral when Newsome and a few others came onstage at a Trump rally in September while staging a counterprotest.

Instead of joining Kessler, he and a handful of other activists marched from the Bronx to Washington over the past 10 days to protest a range of issues, including food insecurity and police brutality.

“I represent a contingent of marginalized people, and [white supremacists] stand in direct opposition to everything we fight for,” Newsome said.

At the Vienna Metro station, V.J. Hyde, a 38-year-old music teacher from Fairfax County, pulled a new stack of posters and a roll of tape from his Whole Foods shopping bag and doled them out to his wife and two daughters.

The family of four and three of their friends came to the Metro station to post “Hate Free Zone” and “Hate Has No Home Here” fliers.

“We’re here because this is a very messed-up time in our country, and our community is front and center,” Hyde said.

He and his family are Jewish, and they have friends who are Asian American. Hyde said he overheard one of his daughters talking to a friend about the white supremacists. She told the friend the rally attendees “hate us.”

“That’s pretty f----- up,” Hyde said.

For some of the protesters, the focus was less on the ­white-supremacist rally than on President Trump.

Holding a “Dump Trump” sign, Mike Holey, 67, of Baltimore said he’s been particularly frustrated by what he called the president’s hesitation to denounce white supremacy and neo-Nazism. He pointed to Trump’s statement that there was “blame on both sides” after violence broke out at the Unite the Right rally last year.

Benjamin Garrett, a Vietnam War veteran who lives in Maryland, raised a sign saying “Trump is a traitor” in block capital letters.

“He gives these people permission,” Garrett said. “Trump is a blatant racist.”

Trump, who was heavily criticized last year for not unequivocally condemning the white nationalists who had organized the rally and a torchlight march through the University of Virginia campus the night before, addressed the Charlottesville anniversary on Saturday, tweeting, “The riots in Charlottesville a year ago resulted in senseless death and division. We must come together as a nation. I condemn all types of racism and acts of violence. Peace to ALL Americans!”

On Sunday morning, tourists making their way through Lafayette Square paused to take in the growing group of protesters gathering on the northeast side of the park.

Brightly colored signs declaring, “From Charlottesville to the White House: Shut down white supremacy” and “No Nazis, no KKK, no fascist USA” lined patches of grass.

Rossana Castillo, 50, a tourist from Grenoble, France, paused as she passed to take photos.

“It’s astonishing to me,” she said of the rally that was expected to bring white supremacists within shouting distance of the White House. “And it is just so sad. I know I am a foreigner, but I love your country. I really do. And I am so grateful these people can be here and have the right to stand up to people like this.”

Later that afternoon, when Kessler and his followers had left the park, Khury Petersen-Smith of the International Socialist Organization — which he said brought hundreds of anti-racist protesters to Lafayette Square — called the day a success.

“If they [white nationalists] hope to spread their message of hate, they’ve been stopped in their tracks,” Petersen-Smith said. “People defied their fear and defied the idea that we should just ignore the far right and instead mobilized to shut them down.”

Hannah Natanson, Teo Armus, Reis Thebault, Peter Jamison, Martine Powers, Michael Brice-Saddler, Fenit Nirappil and Antonio Olivo contributed to this report.