The vote was 71-27, with 18 Republicans supporting the prominent Latino Democrat.
Castro, 39, has served for three terms as mayor of San Antonio, and was the keynote speaker at the 2012 Democratic National Convention. His twin brother, Joaquin, is a Democratic congressman.
Obama nominated Castro after Kathleen Sebelius' decision to resign as Health and Human Services secretary prompted a reshuffling of his Cabinet. The previous HUD secretary, Shaun Donovan, is in line to replace Sylvia Mathews Burwell as budget director, after Burwell was confirmed as Sebelius' successor.
Castro's nomination moved swiftly through the Senate even as Majority Leader Harry Reid (D-Nev.) has raised the specter of further changes to procedural rules that govern the confirmation of presidential nominees. Last fall Reid changed long-standing Senate filibuster rules to allow nominees to advance by a simple majority vote instead of a 60-vote threshold.
The next round of changes could be aimed at reducing blocks of time reserved for debating nominations. Democrats complain these delays have prevented the Senate from quickly moving on to other issues. Reid's proposed "use-it-or-lose-it" rule would require senators to speak during what are now as long as 30-hour blocks of time set aside for debate.
Castro becomes the second Latino in Obama's Cabinet, joining Labor Secretary Thomas Perez.
Follow @mikememoli for more news out of Washington.