A key piece of California’s strategy to address its homelessness crisis was narrowly approved by voters in the state, The Associated Press determined on Wednesday, in a stunningly close margin that had Democrats on edge for more than two weeks.

The measure, known as Proposition 1, includes a $6.4 billion bond to fund treatment and housing for homeless people with severe mental illnesses and addiction. Last year, when Gov. Gavin Newsom and a bipartisan group of California legislators placed Proposition 1 on the spring ballot, early polls suggested that it would pass easily.

Its approval was considered such a sure thing that most voters and political donors were scarcely aware that opposition existed. But after the March 5 election, it took 15 days of tallying mail-in ballots for The Associated Press to determine that the measure had squeaked by.

The count took so long that Mr. Newsom decided to postpone his annual state of the state address, which was originally scheduled for Monday, because he had wanted to celebrate Proposition 1 during his speech and highlight his efforts on homelessness and mental health.

On Wednesday, the governor framed the win less as a close call than a bold choice by Californians who have been frustrated for years with the scale of the state’s homelessness problem.

“This is the biggest change in decades in how California tackles homelessness, and a victory for doing things radically different,” Mr. Newsom said in a statement. “Proposition 1’s passage means we can begin repairing the damage caused by decades of broken promises and political neglect to those suffering from severe mental illness.”