NEW YORK, JUNE 12 -- The Dow Jones industrial average soared 40 points today to within a hair's breadth of its all-time high, thanks to a rally in the final hour of trading driven by computerized trading.

Analysts attributed the last-hour explosion, which took the Dow from 2900 to as high as 2942, to traders continuing to withdraw from positions before Friday, when stock index futures, index options and common stock options all expire. Such unwinding activities were also cited for last Friday's activities, when the Dow fell 34 points, and on Monday, when it bounced back 30 points.

The last-hour surge took the Dow to within 2 points of its record close of 2935.20, set on June 4.

Overall, the market was featureless until the computerized program trading hit, said technician Edward Nicoski at the brokerage Piper Jaffray and Hopwood. ''The technology stocks and the energy stocks were firm, as on Monday, but there wasn't too much else to attract attention,'' he said.

At the close, the Dow stood at 2933.42, up 40.85, with advances outpacing declines by almost 2 to 1. Volume was 157 million shares.

Analysts said that a sparkle in the London stock market, plus a much better report for U.S. semiconductor manufacturers from the Semiconductor Industry Association, helped tilt the early market balance toward the bulls. A marginally firm domestic bond market also helped.

With an hour left in trading expiring June Standard & Poor's 500 futures surged to session-high premiums against cash values, posting hefty 160-basis points premiums. At the same time, newly active September S&P 500 futures soared to successive new session highs well above fair value.

Procter & Gamble closed up 3 1/4 at 84 1/4, Merck up 2 5/8 at 83 3/8 and 3M up 2 at 85 1/8. General Electric, GM and Exxon also posted full-point gains.

The Dow transports rose only 6.75 points to 1208.76, although the utilities gained a more impressive 1.82 to 215.04.

Among broad stock indexes, the S&P 500 was up 4.62 at 366.25, the NYSE Composite up 2.24 at 199.66, the Value Line up 1.54 at 290.80, the Amex Market Value up 1.99 at 364.31 and the Nasdaq Composite -- which outperformed the blue-chip measures in earlier trading -- up 3.77 at 466.56.