Oswald was also in contact with Cuban officials at the same time, it has emerged.
The new revelation will fuel a long-standing conspiracy theory that the USSR was behind the slaying of JFK because of several attempts by the US CIA to assassinate Fidel Castro, leader of the communist regime in Cuba.
In another twist, the files show the CIA and FBI were aware that Oswald made the trip and he was heard speaking at the embassy in "broken Russian," but he was never interviewed or apprehended upon his return.
One of thousands of new documents released by the US National Archives details that Oswald met KGB agent Valeriy Vladimirovich Kostikov, a senior agent in the "13th Department" responsible for assassinations, in Mexico City's Soviet embassy on September 28 1963, less than two months before the killing.
The report says: "According to an intercepted phone call in Mexico City, Lee Oswald was at the Soviet Embassy there on 28 September 1963 and spoke with the Consul, Valeriy Vladimirovich Kostikov."
The document says the CIA learned of the visit when it intercepted a call he made to the Soviet Embassy three days later on October 1, "identifying himself by name and speaking broken Russian".
The report said: "He asked the guard who answered the phone whether there was 'anything new concerning the telegram to Washington.'"
One agent replied: "Oswald wrote me in early 1962 to help expedite an exit visa for his wife. Why in the world would he tell a plopper like that?"
A Senator replies: "In any event, he told what the agent knew was lies, and what I am trying to get at is there was no analysis within the bureau of any of this.
"He even goes to Mexico City, contacts the Cuban consulate and the Soviet embassy, happens to be in contact – we don't know if there is anything sinister about it – with an agent who is known to be KGB by the FBI and by the CIA, and suspected of being Department 13, which is their assassination and sabotage squad.
"In any event, he then returns to the United States, is never again interviewed by the FBI."
A separate memorandum dated July 1969, entitled "An investigation of Lee Harvey Oswald in Mexico", said he was also seen at a party in Mexico in late September, 1963.
It said he went to the party hosted by Mexican playwright Elena Garro de Paz with two other Americans.
Oswald, a communist former US Marine who had defected to Russia in 1959 and married there before returning to the US, spent six days in Mexico.
Hugh Aynesworth was a reporter for The Dallas Morning News who covered the assassination from day one.
He has investigated the case ever since, exploring countless conspiracy theories.
He said: "There's been a lot of speculation over the years about Oswald's trip to Mexico.
"While there, Oswald met with Cubans and Russians."
"The CIA had both the Russian and Cuban embassies bugged.
"So they knew exactly what he said, who he met with, and they've kept this secret."
After the death, The Warren Commission was set up to investigate circumstances leading up to the assassination.
It produced The Warren Report which concluded Oswald had acted alone.
However, the new documents suggest the FBI's failure to properly investigate de Paz's story could have "damaged" the Warren Report.
The report says: "the credibility of the Warren Report would be damaged all the more if it were learned that these allegations were known and never adequately investigated by the competent American authorities."
A top-secret document dated December 1 1963 from FBI Director J Edgar Hoover to Marvin Watson, a special assistant to President Lyndon Johnson, reveals Russia feared it would be implicated in the assassination, but denied any involvement.
It described the reaction inside the communist party to be one of genuine surprise amid fears the assassination was part of a right-wing coup to take over the US government.
It said a reliable source in Russia at the time said the news "was greeted by great shock and consternation and church bells were tolled in the memory of President Kennedy.
It added: "According to our source, officials of the Communist Party of the Soviet Union believed there was some well-organized conspiracy on the part of the 'ultraright' in the United States to effect a coup.
The memo, citing an unnamed source, says "Soviet officials claimed that Lee Harvey Oswald had no connection whatsoever with the Soviet Union. They described him as a neurotic maniac who was disloyal to his own country and everything else."
A memo from the CIA Director of Security to CIA Headquarters, dated March 11, 1964, said George M Lesnik, a former KGB agent in Moscow on the day of the Kennedy assassination, "dashed to his office" to look at Oswald's file.
It said: "When he found the file he reviewed it and found that Oswald had not been used or even approached for use by the Russian intelligence."
However, another document said the Cuban ambassador to the UN and his staff reacted with "happy delight" days after the assassination.
It was revealed in The Warren Report that Oswald also had connections to Fair Play for Cuba, a grassroots movement to support the Cuban revolution.
The Cuban ambassador was instructed to govern their staff, and to "cease looking happy in public," the report said.
Russian Foreign Ministry Spokeswoman Maria Zakharova said of the new information: "For decades, information has been kept under lock and key.
"If even here wild insinuations are hurled at Russia, that would be a shame, because it is information, and not disinformation that people want."