U.S. Secretary of State John Kerry told college graduates on Friday that their diversity is "Donald Trump's worst nightmare" and that it's their job to stop the spread of violent extremism.

Speaking to an estimated audience of 25,000 at Northeastern University's commencement, Kerry drew heavy applause when he noted the many races and religions among the graduates, and then directed a jibe at the presumptive Republican presidential nominee.

"You are the most diverse class in Northeastern's history," he said. "In other words, you are Donald Trump's worst nightmare."

Trump has angered many by comments he has made about Hispanics and Muslims, among other groups. He backs building a wall along the U.S.-Mexico border and wants to deport the millions of people in the U.S. illegally. He has also proposed banning Muslims from entering the U.S.

The Democratic secretary of state assured graduates that the United States and its allies are winning the battle against terrorists in Iraq and Syria. But he added that the U.S. won't be successful in the long run if the world continues to turn away from other problems that fuel the production of terrorists at what he said is an "alarming" rate.

"Your mission is to make jobs not just in a few places but many places," he said. "Doing this is not about charity, it's not about giving something for nothing. It's about building our own security and preventing the conflicts of the future."

During his speech at Boston's TD Garden, Kerry praised the work of President Barack Obama's administration on climate change and public health, but called on graduates to go further.

He blasted climate change deniers and called the issue "one of the greatest challenges of our time." He added that the global agreement on climate change reached in Paris last year is only the start of the solution.

"Last March was the hottest March in recorded history. Last year was the hottest year in recorded history," he said. "The facts are simply staggering."

Kerry, who became secretary of state in 2013, was a longtime U.S. senator from Massachusetts and was a prosecutor in the state. He earned a law degree from Boston College in 1976 after graduating from Yale University. He previously delivered the commencement address at Northeastern in 2000.

Talking for half an hour, Kerry described a world filled with heavy challenges. He drew on the spread of the Zika virus, the wide gap between rich and poor, and on the 2013 Boston Marathon bombings.

"Boston and Northeastern need no lesson in how important it is to win the battle against terrorists," he said. "There can be no peace without eliminating this scourge."

But he added that the graduates have the education and character to confront those challenges, and urged them to play a role in the global community. He ended on an optimistic note, paraphrasing former South African President Nelson Mandela.

"All the hardest jobs seem impossible until they are done," Kerry said.