Prime Minister John Key was mobbed by Mexican school children as he accompanied President Enrique Pena Nieto on a impromptu walkabout today.

The pair held formal talks in Mexico City, as part of Key’s whirlwind tour of four Latin America countries.

After the hour long bi-lateral meeting, they formally announced that Mexico will support New Zealand’s bid for a non-permanent seat on the UN Security Council in 2015/16.

The visit risked being disrupted by a mass protest in the metropolis over Pena Nieto’s education reforms. The 5000 strong demonstration, could be seen snaking underneath the hill-top palace, along La Reforma, one of the city's main arteries.

As an official military welcome ended and the pair entered Chapultepec Castle, shouts could be heard from the protesters.

But the pair were all smiles as they approached the group of school children who had waited in the hot sun, waving Mexican and New Zealand flags.

The youngsters screamed as the two leaders briefly chatted with them. A Mexican official said the detour, after inspecting Mexican troops, to talk to the group of around 40 children was unusual. Official visits usually follow strict protocols.

Key is the first foreign leader to be received by Pena Nieto, who was inaugurated in December. They were accompanied by Key’s wife Bronagh, and Mexico’s glamorous First Lady Angelica Rivera de Pena.

The talks were held inside the castle - underneath an imposing mural by revolutionary painter Diego Rivera.

Afterwards, the pair held a joint press conference in which Key thanked Pena Nieto for his support at the Security Council and congratulated him on his election.

The pair also talked about the Trans Pacific Partnership negotiations, which Mexico joined in October.

“New Zealand exporters to Mexico currently face tariffs of up to 60 per cent on some goods. The successful completion of TPP negotiations will create further opportunities for New Zealand businesses wanting to export, expand and invest overseas.

The two countries celebrate four decades of diplomatic relations this year. Key has invited Pena Nieto to travel to New Zealand.

Earlier Key laid a wreath at Los Ninos Heroes, a monument to six teenage cadets who died defending the castle in 1847.

After a state banquet in the castle – the backdrop to the 1996 Romeo + Juliet film - Key leaves Mexico this evening to travel to Colombia for talks with President Juan Manuel Santos.