A Bay Area Rapid Transit (search) walkout was averted early Wednesday when unionized workers reached an agreement with management less than two hours before the trains that carry more than 300,000 riders each day were threatened to be shut down.

The deal was announced by BART spokesman Linton Johnson (search) just before 3 a.m., ending more than four days of round-the-clock negotiations that would have led to gridlocked freeways, overcrowded buses and ferries and a messy commute.

"We are happy that we have been able to work out a reasonable, tentative agreement," said Harold Brown, the president of the Amalgamated Transit Union, Local 1555 (search). "Our primary concern has always been rider safety and service. We are glad that riders will not be inconvenienced by a strike."

The 2,300 unionized BART workers were expected to be back on the job when the trains were scheduled to resume running shortly after 4 a.m. Wednesday.

Details of the agreement were not expected to be released until after it was ratified by BART's 2,300 unionized workers sometime over the next 10 days.

"We had to deal with some very difficult and complex issues," BART General Manager Tom Margro said. "This contract is fair to our employees and protects the interests of our riders."

Roxanne Sanchez, the BART chapter president of the Service Employees International Union, Local 790 (search), said the agreement would promote health care standards for workers and also includes affordable pay increases.

Dozens of union members were at the news conference announcing the deal. Many were laughing and hugging each other; some even were holding back tears.

The contracts between BART and its workers expired last Friday but the unions delayed setting a strike date until the July 4 holiday. The deal came after union leaders twice extended their 12:01 a.m. Wednesday strike deadline.

Negotiators for BART and the unions met for about 26 hours over the weekend and were at the table almost continuously starting Monday morning.

BART management had said the major sticking point was finding a compromise that would help the agency deal with a projected $100 million, four-year deficit while not further burdening riders, who have already been hit with fare increases and parking charges.

"We are confident the agreement, when ratified by the unions' members, will put BART on sound financial footing now and for the future," said Joel Keller, president of BART's Board of Directors.

The union in its last proposal called for annual raises of between 2 percent and 4 percent over three years, and offered to triple union contributions for health benefits to $75 a month.

San Francisco Bay area transportation officials had urged commuters on Tuesday to consider forming car pools, riding ferries, working from home and even taking vacations to keep the freeways moving if there was a strike.

The last BART strike was in 1997 and lasted six days.