Castro, the 44-year-old grandson of a Mexican immigrant, said he was running for president "because it's time for new leadership, because it's time for new energy and it's time for a new commitment to make sure that the opportunities that I've had are available to every American."
He made the announcement during the longest government shutdown in U.S. history, and as the field of 2020 contenders widens and anticipation grows around bigger names still considering runs.
Castro was San Antonio's mayor for five years and U.S. housing secretary in President Barack Obama's second term. He became the second Democrat to formally enter race, after former Maryland Rep. John Delaney.
Sen. Elizabeth Warren of Massachusetts has also started an exploratory committee for president, and four other Democratic senators are taking steady steps toward running. Hawaii Rep. Tulsi Gabbard, the first Hindu elected to Congress, said this week she is planning a bid, too.
For his part, Trump said he isn't worried about the burgeoning field of Democratic opponents. He has already announced that he's running for re-election.
"I love what I see," Trump said Saturday night when asked about the competition during a telephone interview with Fox News Channel. He recited a list of what he views as his accomplishments, including low unemployment, tax cuts and trade deals.
"I don't know. How does somebody beat that?" the president said.
Asked to identify the one Democrat he'd like to run against, Trump named former Vice President Joe Biden, a two-time presidential candidate who has yet to announce his intentions for 2020.
The impasse over paying for a border wall that Trump made a central part of his 2016 campaign has led to the partial federal closure. That stalemate, along with Trump's hard-line immigration stands, drew sharp rebukes from Castro.
"There are serious issues that need to be addressed in our broken immigration system, but seeking asylum is a legal right. And the cruel policies of this administration are doing real and lasting harm," he said.
He argued for securing the border in a "smart and humane way."
"There is no way in hell that caging babies is a smart or a right or good way to do it. We say no to building a wall and say yes to building community. We say no to scapegoating immigrants," he said.
Joining Castro at the campaign kickoff was his twin brother, Democratic Rep. Joaquin Castro, chairman of the Hispanic congressional caucus and a frequent Trump critic. The Spanish-style plaza in the Castro twins' boyhood neighborhood was packed with supporters who streamed through the gates between a mariachi band. Castro had said leading up to his announcement that a Latino candidate was a must in the 2020 field.
Sen. Kamala Harris of California this past week published a memoir , a staple of presidential candidates. Former Texas Rep. Beto O'Rourke is doing little to dim speculation that he might jump into a field that has no clear front-runner.
Castro is aware he lacks the name recognition of potential 2020 rivals or the buzz surrounding O'Rourke, whose flirtations with 2020 have tantalized donors and activists after a close race last year against Sen. Ted Cruz, R-Texas.
Even some supporters at Castro's announcement could be torn if O'Rourke gets in the race. Diana Delrosario, a social worker in San Antonio, warned she might cry while she recounted how Castro once went out of his way as mayor to help wheel her mother out of a restaurant.
"I have this heart for Julian. But it's going to be a big discussion if Beto decides to run," said Delrosario, 45.
Castro, who has repeatedly dismissed talk that an O'Rourke candidacy would complicate his own chances, has framed the neighborhood and his upbringing as the story of an underdog.
He was raised by a local Latina activist, and after a brief career in law, was elected mayor of the nation's seventh-largest city at 34. It wasn't long before Democrats nationally embraced him as a star in the making, particularly one from Texas, where a booming Hispanic population is rapidly changing the state's demographics and improving the party's fortunes.
Castro delivered the keynote speech at the 2012 Democratic National Convention. Two years later, Obama picked him to lead the Department of Housing and Urban Development.
He was on the short list of Hillary Clinton's potential running mates in 2016. During Castro's trip this past week to Nevada, one state Latino business leader told Castro that he should again be a top contender for vice president if his campaign falls short.
Like other Democrats running, Castro has said he will not accept money from political action committees tied to corporations and unions, and he has sought to introduce himself to voters as a champion for universal health care and affordable housing.
Follow Paul J. Weber on Twitter: www.twitter.com/pauljweber
Associated Press writer Darlene Superville contributed to this report.