Santa Fe Industries Inc. and the Southern Pacific Co. ended years of off-again, on-again courtship yesterday by announcing that they have agreed in principal to merge and form the nation's third-longest railroad.

Assuming it wins approval from the stockholders of both companies and the Interstate Commerce Commission, the merger would create a western rail giant and continue a trend that has eliminated many storied railroad names and left the nation with nothing but superpowers and short lines.

The proposal also could lead to the first transcontinental railroad, because Santa Fe has expressed interest in Consolidated Rail Corp. (Conrail), the federally owned northeastern road the government is trying to sell. Conrail connects conveniently with a merged Santa Fe-Southern Pacific at both Chicago and St. Louis.

Santa Fe Chairman John J. Schmidt called Transportation Secretary Elizabeth Hanford Dole yesterday and told her that Santa Fe will continue an extensive study of Conrail, a Transportation Department official said.

Schmidt told reporters the same thing at a press conference in Tulsa yesterday, but added that a definitive decision on Conrail will be reached later. Some industry analysts believe that Schmidt was using a feigned interest in Conrail to cover the reopening of negotiations with Southern Pacific.

The merger of the two railroads long has been regarded as logical, especially since other recent mergers have turned the Burlington Northern and the Union Pacific into western giants with about the same annual rail revenue of Santa Fe and Southern Pacific combined.

Before the days of railroad deregulation, such a merger proposal would have been tied up in the ICC for years. Now the commission is obliged to act within 31 months. Recent history would indicate ICC approval, according to industry analysts.

The companies plan to merge their other activities--primarily real estate and timber--by the end of this year, they said. "We fully realize we cannot have common management of the railroads" until after ICC action, a Santa Fe spokesman said.

Henry H. Livingston, an analyst with Kidder Peabody, said that, if the merger trend "is carried through to its logical conclusion," the nation will be left with one or two large railroad companies that either will "get broken up or be nationalized because they are too noncompetitive and too spread all over the map to remain alive against highway and waterway competition."

Railroad managements have defended mergers in recent years as necessary to give them the streamlined operation needed to compete with trucking companies. Elimination of interchange points between railroads that merged, for example, has reduced the time advantage that truckers were building over railroads on the interstate highway system.

Under the agreement announced yesterday, the two firms will become subsidiaries of a holding company, Santa Fe Southern Pacific Corp. Schmidt will be chairman and chief executive of the holding company, and R.D. Krebs, president of Southern Pacific, will become president and chief operating officer.

B.F. Biaggini, chairman and chief executive officer of Southern Pacific, is expected to retire, according to spokesmen for both companies. Biaggini was widely reported to be a problem for Santa Fe when merger talks with Southern Pacific last broke off in 1980.

At a news conference in San Francisco, Biaggini said the "merger of equals" will produce "one of the world's largest and strongest companies. It is good for the stockholders, good for the employes and good for the public we serve in many ways," he said.

Upon consummation of the merger, each outstanding share of Southern Pacific will be exchanged for 1.543 shares of common stock in the new holding company. Each share of Santa Fe stock will be exchanged for 1.203 shares of the new holding company.

The merged railroad would be third in route miles with 25,700, second only to CSX Corp. in freight revenue with a 1982 total of $3.93 billion, and second in revenue-ton miles at 138.9 million.

Southern Pacific employs 41,000 people; and Santa Fe, 34,241. Biaggini said both companies would retain their separate offices, and no employe changes were anticipated.

Last year, Southern Pacific earned $120.1 million ($2.16 a share) on revenue of $3.1 billion. Santa Fe recorded 1982 profits of $180.2 million ($2.08) on revenue of $3.2 billion.

If the merger results in the first transcontinental system, it would be a fitting role for Southern Pacific. The SP is a direct descendant of the Central Pacific, one of the two railroads that were joined with the driving of the Golden Spike at Promentory Point, Utah, in May 1869.