TIJUANA, MEXICO -- On a given day, up to 12 million gallons of raw sewage from this booming city in the northwestern corner of Mexico flows untreated into the Tijuana River. Illegal aliens wade through it to cross into the United States, people use it to wash their cars, and farmers siphon off some of its flow to irrigate crops. All this might not make much difference to Americans, except that the Tijuana River does not recognize the U.S. border. Its "black waters," as the Mexicans describe the river's contents, flow northwest into California, meander through a federally protected salt-water estuary and empty into the Pacific Ocean just south of Imperial Beach. As a result, 2 1/2 miles of U.S. beaches north of the Mexican border have been closed for most of the last 10 years. The 2,500-acre estuary -- one of only three of its kind in the United States -- is gradually being poisoned. Endangered species of birds that live there are disappearing. And nearby communities have been plagued by mosquitoes and a variety of diseases. Among the illnesses associated with the reeking, greenish-black river, according to U.S. health officials, have been amoebic dysentery, vibrio cholera, staphylococcal disease, hepatitis, encephalitis and two outbreaks of malaria in the last three years. Coliform counts, indicators of fecal matter in water that provide the basis for closing beaches, have also turned up polio agents in the Tijuana River. Consisting almost entirely of raw sewage, the river ranks as the most polluted in the United States, officials in San Diego say. Long a sore point in relations between Tijuana and San Diego, the Tijuana River has come to symbolize a problem of increasing concern along the 2,000-mile U.S.-Mexican border: worsening air and water pollution. Smog that drifts into the United States from Mexican border cities, flows of untreated sewage and the dumping of industrial wastes have raised fears that, as one U.S. environmentalist recently put it, the border could turn into "a 2,000-mile Love Canal," the highly polluted area near Niagara Falls. Now, however, authorities of both countries appear to be turning their attention to the problem. Among several accords reached during a visit to Washington by President Carlos Salinas de Gortari earlier this month was an agreement in principle to build a unique joint sewage treatment plant on U.S. soil just north of this city. The agreement is viewed as another example of increased Mexican cooperation with the United States under the Salinas administration. The $144 million project -- including a 25 million-gallon-a-day treatment plant and a pipeline to carry treated waste water to the Pacific Ocean -- is aimed at cleaning up the Tijuana River and saving the estuary. Details are now under negotiation by U.S. and Mexican representatives at the International Boundary and Water Commission. "We are moving rapidly to resolve sanitation and pollution problems on the border," said Narendra Gunaji, the U.S. head of the 100-year-old commission. He said he expects the new joint sewage treatment plant to start operating by 1993. Pollution problems on the border long have been overshadowed by those of illegal aliens and drug trafficking. In recent years, however, the problems have worsened as populations on both sides of the line have grown. Many of the new inhabitants are poor Mexicans who live in unauthorized settlements lacking sanitation services. One of the most serious problems, U.S. officials say, is the pollution of the Rio Grande, which forms the border between Mexico and Texas. According to the International Boundary and Water Commission, up to 25 million gallons a day of raw sewage flow into the river from Nuevo Laredo, the Mexican city across the border from Laredo, Tex. At El Paso, where the commission is based, water pollution problems have been supplemented by winter smog that drifts over from the sister city of Ciudad Juarez. As in the rest of Mexico, cars in Ciudad Juarez are not required to have antipollution devices, and controls on industrial emissions are not as strict as on the U.S. side. Near Mexicali, opposite the California town of Calexico, sewage and industrial wastes have severely contaminated the New River, which flows north to California's Salton Sea, a national wildlife refuge. In the case of the Colorado River, Mexico suffers the consequences of high salinity acquired in the water's usage for irrigation as the river passes through seven U.S. states before entering Mexico's Gulf of California. The United States is obligated under a 1974 agreement to reduce the salinity. Here in Tijuana and neighboring San Diego County, pollution from the Tijuana River has been compounded by breakdowns and overflows of Tijuana's sewage treatment system. After rejecting previous American proposals for construction of a joint treatment plant as too costly, the government of Salinas' predecessor, Miguel de la Madrid, opted to build its own plant, which de la Madrid proudly inaugurated in 1987. However, the plant, the first of its kind in the country, ran into problems from the start. With capacity to treat 17 million gallons of sewage a day, it was inadequate to handle the 22 million gallons a day actually pumped into it, much less the overall 32 million gallons a day produced by Tijuana's 1.3 million residents. The plant promptly broke down in October 1987, remaining out of service for seven months. During that time, raw sewage was discharged directly into the Pacific Ocean surf, a source of concern for San Diego because of currents that occasionally flow north. Even now, San Diego city officials worry about the surf discharge of sewage that they say is inadequately treated at best. "The Mexicans are very proud of what they've done," said one official, "but it's not up to the standards we have here. It's a touchy issue." While U.S. authorities have declared beaches just north of the border unsafe, said California state parks official Ed Navarro, "directly across in Mexican waters, activity goes on as if there's no problem." Although the agreement for a new joint treatment plant is generally welcomed, some U.S. officials remain bitter about the whole issue. "I don't think anyone is thrilled about having to pay to treat someone else's sewage," said San Diego County supervisor Brian Bilbray, noting that the U.S. government is expected to foot $100 million of the new plant's cost.