In answer to Mr. Lyons’s questions, the man, wearing a red shirt that dwarfed his thin frame, said he was bipolar, schizophrenic and homeless. He was looking for help because he did not think his prescribed medication was working.

In the past, paramedics would have taken the man to the closest hospital emergency room — most likely the nearby WakeMed Health and Hospitals, one of the largest centers in the region. But instead, under a pilot program, paramedics ushered him through the doors of Holly Hill Hospital, a commercial psychiatric facility.

“He doesn’t have a medical complaint, he’s just a mental health patient living on the street who is looking for some help,” said Mr. Lyons, pulling his van back into traffic. “The good news is that he’s not going to an E.R. That’s saving the hospital money and getting the patient to the most appropriate place for him,” he added.

The experiment in Raleigh is being closely watched by other cities desperate to find a way to help mentally ill patients without admitting them to emergency rooms, where the cost of treatment is high — and unnecessary.

While there is evidence that other types of health care costs might be declining slightly, the cost of emergency room care for the mentally ill shows no sign of ebbing.

Nationally, more than 6.4 million visits to emergency rooms in 2010, or about 5 percent of total visits, involved patients whose primary diagnosis was a mental health condition or substance abuse. That is up 28 percent from just four years earlier, according to the latest figures available from the Agency for Healthcare Research and Quality in Rockville, Md.

By one federal estimate, spending by general hospitals to care for these patients is expected to nearly double to $38.5 billion in 2014, from $20.3 billion in 2003.

The problem has been building for decades as mental health systems have been largely decentralized, pushing oversight and responsibility for psychiatric care into overwhelmed communities and, often, to hospitals, like WakeMed.

In North Carolina, the problem is becoming particularly acute. A recent study said that the number of mental patients entering emergency rooms in the state was double the nation’s average in 2010.

More than 10 years after overhauling its own state mental health system, North Carolina is grappling with the consequences of a lost number of beds and a reduction in funding amid a growing outcry that the state’s mentally ill need more help.

In Raleigh, where the Dorothea Dix Hospital — a state psychiatric institution that served the area for more than 150 years — was closed in 2012, mentally ill patients began trickling into hospital emergency rooms.

Hospitals, which cannot legally turn away any patient seeking care, say the influx of psychiatric patients is straining already busy E.R.’s and creating dangerous conditions.

This spring, University Medical Center of Southern Nevada in Las Vegas declared an “internal disaster,” shutting its doors to arriving ambulances for 12 hours, after mental patients filled up more than half of its emergency room beds. A suicidal patient took out a gun and shot herself in the head while in a hospital emergency room in New Mexico in January.

With a crisis facing states, communities and hospitals across the country, experts say no clear solution has emerged. St. Joseph’s Hospital Health Center in Syracuse created a separate psychiatric emergency department. Interim LSU Hospital in New Orleans opened a 10-bed mental health emergency room extension six years ago that is typically full.

But in Raleigh, the goal is slightly different: keep the psychiatric patients out of the hospital emergency room altogether.

The problem facing North Carolina and other states is a legacy of the 1960s, when warehousing of the mentally ill in large psychiatric hospitals was seen as inhumane.