Gulf Oil Corp. has sold off the last of its real holdings in the town Gulf bought -- Reston -- to a group of local investors.

Gulf Reston Inc., a Gulf subsidiary, announced yesterday that it has sold its remaining 20 commercial properties for $40 million to an investment group consisting of Louis T. Donatelli, Rodger W. Klein and Winkler Co.

The properties include 3 shopping centers, 6 apartment complexes, 10 office buildings and the Reston International Center Complex, a package that had an assessed value of more than $40 million in 1979.

At the time Gulf had planned to sell the same properties to an investment group of six large pension funds managed by Coldwell Banker, a major commercial real estate firm.

But the deal fell through. "The discussions were terminated by mutual consent," according to a Gulf spokeswoman.

Earlier in 1978, Gulf had sold approximately 3,500 acres of undeveloped land in Reston to a Mobil Oil Corp. subsidiary for $30 million. When Gulf began to sell its real estate holdings, it said it did do to concentrate on energy.

Reston was the creation of Robert E. Simon, a New Yorker who dreamed of building a well-planned, well-designed urban complex suitable for the rolling countryside where it was built. In the late 1960s, Simon ran out of cash when sales failed to meet projections. In late 1967, Gulf Oil bought Simon out.