MOSCOW (AP) _ Former President Jimmy Carter and Mikhail S. Gorbachev, the Soviet leader, had an informal discussion Wednesday of topics ranging from superpower relations to the fact that both are country boys.

A Foreign Ministry spokesman said Carter, who served one term and lost the 1980 election to Ronald Reagan, arrived Tuesday with his wife Rosalynn at the Soviet government's invitation.

Carter and Gorbachev joked about their rural roots and the tendency of superpower leaders to be critical of one another.

''Two farmers can't be antagonistic toward each other,'' Carter said.

Gorbachev grew up in the agricultural Stavropol region of southern Russia and Carter was a peanut farmer in Plains, Ga.

Tass, the official news agency, said Mrs. Carter accompanied her husband to the Kremlin. Its dispatch said the former president and Gorbachev spoke at length about the Middle East, which was among Carter's main spheres of interest when in office.

Gorbachev said the Soviet Union was prepared to work for the success of an international Middle East peace conference if ''its formula would take into account the interests of all Arabs and Israel and would preclude its transformation into an 'umbrella' for separate deals,'' Tass reported.

He said the Soviets recognize that the West has legitimate interests in the Middle East, but it should not pursue ''unrealistic objectives in settling the crisis.''

American and Soviet photographers were allowed to take pictures during the first few minutes.

Also attending the session was Anatoly F. Dobrynin, who was Soviet ambassador to the United States for nearly 25 years and now is Communist Party secretary for international affairs. Carter greeted him warmly.

A U.S. Embassy spokeswoman said the Carters would be in Moscow through Friday and would meet with American reporters Thursday.