WASHINGTON (AP) _ The government has reached agreement to recover more than $3 million from two oil companies that allegedly obtained 64 oil and gas leases improperly, the Justice Department said Tuesday.

Williams Exploration Co. of Houston and Patrick Petroleum Corp. of Michigan in Jackson, Mich. agreed to the settlement, said Acting Assistant Attorney General Richard K. Willard.

Under terms of the agreement, Willard said, $2,310,000 must be repaid to the government within 10 days - $2 million by Williams Exploration and $310,000 by Patrick Petroleum.

The agreement requires Patrick Petroleum to pay the government an additional $700,000, plus 10.33 percent annual interest in three annual installments ending on July 1, 1987. This brought the total amount of the settlement to at least $3,010,000.

It was alleged that the two firms obtained 64 oil and gas leases by ''violating regulations governing federal award of leases through a lottery program,'' the department said.

Willard, who heads the department's Civil Division, said the agreement requires cancellation of 41 of the leases and requires higher royalty payments to the government on the 12 leases the companies will retain.

Eleven other leases were either terminated or expired earlier.

The government contended that the two companies violated federal regulations in obtaining leases in Montana, North Dakota and South Dakota from winners of the lease lotteries from 1975 to 1979.

The lottery program, known formally as the Federal Simultaneous Oil and Gas Leasing System, is operated by the Interior Department' Bureau of Land Management.