As the budget deficit agreement appeared headed for derailment yesterday, the stock and bond markets reacted with virtual indifference.

Apparently shrugging off concerns that the loosely stitched budget deal was fast unraveling, the Dow Jones industrial average rose 27 points and the benchmark 30-year Treasury bond gained nearly a full point. Buying by program traders and institutional bargain hunters fueled an afternoon rally.

Wall Street traders and economists offered a variety of explanations for the market's equanimity in the face of political chaos. Most comments reflected the notion that financial markets never really expected Washington to craft meaningful budget cuts in the first place, and so were not surprised when a relatively significant package had trouble gaining political approval.

"I don't think the market looks at this as a long-term solution anyway," said economist Jim Winder, who emphasized that he was giving his personal opinion of the market's reaction and was not speaking for his employer, Merrill Lynch & Co.

But neither Winder nor anyone else ruled out the importance of working out a budget solution of some sort.

Wall Street officials said that even a weak package, one that does little to provide a long-term remedy to the nation's cost overruns, would be welcome, and largely for one reason: Alan Greenspan.

Almost more important than whether modest efforts are made to ease the budget deficit is the Federal Reserve Board chairman's virtual promise this week to lower interest rates if Congress pushes through a budget deal close to the compromise now on the table.

"I think if they actually vote down the deal, that will change the attitudes of Greenspan and the Fed and the markets will react very negatively," said James R. Jones, chairman of the American Stock Exchange.

Stephen Bell, managing director of Salomon Brothers Inc., agreed. "If it isn't passed, I think you'd see a terrible reaction not only in U.S markets but overseas. If this pact fails in some really definite way, you'll see people lose confidence in {U.S} markets. We don't think the pact is a cure-all, but without it you'd see a very serious downturn in the markets." For that reason, he said, the markets expect eventual passage of a budget package, despite the current glitches.

The absence of any nervousness on Wall Street yesterday may bespeak more political sophistication than apathy. Because Congress always works until the last minute, a number of traders viewed yesterday's backing and filling as business as usual. Some ventured that Wall Street activity is being driven more these days by the fluctuation in oil prices, which has in many ways eclipsed the budget talks. Oil prices yesterday were up 39 cents to $36.93 per barrel yesterday, a negligible increase that analysts said wasn't enough to dampen the modest rally.

Yesterday's gain for the Dow average of blue-chip industrials did not reflect the full action on the broader market, where issues were mixed for the day and declining stocks outpaced advances for most of the day.

Particularly hard hit was the high-technology group, where Digital Communications plunged nearly 30 percent on a dismal earnings report and a number of other issues fell in sympathy.

At the close, the Dow stood at 2516.83, up 27.47, although broad indexes were less resilient and declines edged advances on the Big Board. New York Stock Exchange volume was moderate at 145 million shares.

Among Dow components at the close, Eastman Kodak rose 1 1/8 to 38 3/8, International Paper gained 1 1/2 to 47 1/2, Procter & Gamble added 1 1/2 to 78 5/8 and USX Corp. tacked on 1 to 32 1/4. But outside of the Dow, some serious losses were posted.

Digital Communications Associates was slammed to a 29 percent loss after reporting first-fiscal-quarter net down two thirds from the year-earlier level. The stock closed down 4 3/8 at 10 5/8.

Among other technology issues, Honeywell fell 3 to 79, Digital Equipment lost 2 3/8 to close at 50 1/8, and Hewlett Packard shed 1 3/4, ending the day at 29 1/4. Unisys continued to be heavily traded following last week's notice of continuing losses, slipping another 1/4 to 3 5/8.

Motorola posted a prominent, 3 1/2 loss at 60 1/2 in reaction to news late Wednesday that McCaw Cellular, the biggest operator in cellular networks, will replace aging Motorola switching and transmission equipment with new hardware from competitor Ericsson GE Mobile Communications, a joint venture of General Electric and Sweden's L.M. Ericsson.

Ingersoll-Rand toppled 5 7/8 to 33 1/4 after the company announced that third-quarter earnings will be lower than most analysts' expectations.

The Dow utilities surged 2.46 to 204.92, lending credence to bullish projections of lower interest rates ahead, but the transports fell 13.49 to close at 869.28 as UAL Corp. slumped 6 3/8 to 105 3/8 as the deadline approaches for employee unions to find financing for a buyout of the airline company.

Broad stock indexes either failed to keep pace with the Dow or posted losses on the day. The Standard & Poor's 500 was up only 1.29 at 312.69, the NYSE Composite up 0.53 at 171.33, the Value Line down 0.45 at 229.89, the Amex Market Value down 1.11 at 308.14, and the Nasdaq Composite down 1.56 at 349.89.

In Tokyo today, stock prices surged, closing sharply higher at the end of morning trading. The 225-share Nikkei stock average rose 785.75 point, or 3.53 percent, to 23,063.94. Yesterday, the index shed 571.20 points, or 2.56 percent, falling to 22,278.19.

Traders said advances in Europe and New York, coupled with lower oil prices and the stronger yen contributed to the rebound.This article was supplemented by wire service reports.