A PORTRAIT by a surrealist painter and writer, which she gave as a gift to her estranged lover, has been bought by the National Galleries of Scotland for more than half a million pounds.

The painting by the British painter Leonora Carrington is the first of her works to enter the national Scottish collections.

It is a portrait of the German artist Max Ernst, who became Ms Carrington's lover in 1937, and with whom she moved to France the same year.

The painting, from 1939, has been bought for £560,000: with £100,000 of the total from the galleries, £150,000 from the Art Fund and £310,000 from the Henry and Sula Walton Fund.

The painting was an important part of the artist's life.

By December 1942, Carrington, from Lancashire, had become estranged from Ernst, and was about to move to Mexico, where she would spend much of the rest of her life.

She and Ernst met in New York, and as a parting gift she presented him with this portrait.

In exchange he gave her a painting titled Leonora in the Morning Light, which remained in her possession until her death in 2011.

Simon Groom, director of Modern and Contemporary Art at the National Galleries of Scotland said: "The NGS has one of largest and most significant collections of Surrealist art anywhere in the world, but until now we have not had a painting by Leonora Carrington. "This extraordinary portrait of Max Ernst is one of her most celebrated works, and is richly woven with imagery which hints at her complex and ambivalent feelings about her lover and fellow-artist.

"We are deeply grateful to the Trustees of the Henry and Sula Walton Fund, and Art Fund, for helping us to make this stunning addition to our collection.”

Carrington was born in Chorley, and was the daughter of a wealthy textiles industrialist.

She was twice expelled from school in England, and was sent to Florence and then Paris, where she developed an interest in art.

She returned to Britain in 1935, where her family expected her to marry, but she had other plans for her life.

While studying painting in London, Carrington met Ernst at a dinner party and they fell in love.

When Ernst returned to Paris, Carrington joined him.

Their friends in Paris included the artists Salvador Dalí, Pablo Picasso, Leonor Fini and Joan Miró, and in 1938 Carrington’s paintings were shown in a major Surrealist exhibition at the Galerie des Beaux-Arts.

In the painting, Ernst is shown in a red robe made of fur or downy feathers, which ends in a fishtail.

In the painting, one of Ernst’s feet is clad in a striped yellow sock.

In his right hand he is holding a green lantern within which is a small horse.

A NGS statement says: "Carrington refused to interpret or explain her work, her short stories, several of which were published in the late 1930s and 1940s, offer clues.

"Horses were important in her writing and her paintings, acting as surrogate self-portraits; it has been argued that her portrait of Ernst captures some of the ambivalence in their relationship, a sense of being emotionally captive and the need to escape Ernst’s shadow."

Following the exchange of paintings in New York, Portrait of Max Ernst subsequently passed into the collection of Pegeen Guggenheim, the daughter of renowned collector and gallerist Peggy Guggenheim.

She gave it to her husband, the British artist Ralph Rumney, and it has been in private collections since.