In terms of narrative clarity, Robert Eggers’ second feature might not shed even as much light as his rather enigmatic debut “The Witch” did, but it shares with its predecessor an uncanny ability to create a sense of wonder—sometimes pleasurable but more often eerie, and sometimes truly frightening. On the most basic level “The Lighthouse” dramatizes the psychological effect of isolation, but it does so with a raft of symbols and weird details that constantly keeps one off balance. It might baffle you, but its visceral impact is undeniable.

On the surface the plot is extraordinarily simple. On the coast of Maine in the late nineteenth century, two men arrive to take over a lighthouse for a month. The older, experienced man is Thomas Wake (Willem Dafoe), a fellow as craggy as the rock on which the structure is set, with a habit of speaking histrionically in quasi-Biblical cadences redolent of a Melville character. Young Ephraim Winslow (Robert Pattinson), by contrast, is a newcomer to the trade, a reticent fellow with a recessive air that suggests a difficult past and emotional trauma.

Wake is an imperious boss, making it abundantly clear that the upper level of the place, where the enormous, circling light is housed, reached by a winding iron staircase topped by a grill he invariably locks after climbing it, is entirely his domain, closed off to Ephraim. The younger man, meanwhile, is assigned all the grunt tasks—trundling wheelbarrows of coal up the slick stones to feed the furnace, cleaning out the filthy cisterns, tossing the refuse into the waves. It’s backbreaking work, and Winslow’s only respite comes in pleasuring himself, using a small figurine he finds in a mattress for inspiration, although he is visited by occasional visions of a seductive mermaid signaling to him from the waters.

The first half of the film consists of Wake basically taunting Winslow, prodding him to share a toast at the meals they share and open up about his past, which Ephraim clearly doesn’t want to talk about, and Winslow seething at being shut off from the light, which seems to endow the grizzled old coot with some mysterious power (at one point a tableau shows him as a Poseidon figure, towering over mere humans like a sea-god) while not knowing what Wake is writing about him in the logbook he keeps under lock and key.

Ephraim must also deal with other irritations—notably the aggression of one of the gulls that circle the place, a nasty creature that must not, Wake tells him, be harmed, since the sea birds are repositories of the souls of dead mariners, and must be treated with respect. That’s easy for Thomas to say, given that he seems never to venture out into the wind and blinding rain, but Ephraim must put up with the bird’s increasingly threatening attacks.

There’s a strong suggestion of the supernatural in all this, of course, and as the film progresses the hint becomes more and more insistent even as human factors dominate. The men’s relationship changes: as they share more and more of the alcohol Wake loves, Winslow loosens up—though his doing so releases impulses he’s been struggling to keep in check. Things erode as the month-long term continues and he cannot keep from dealing with the gull in the film’s most disturbing sequence.

That’s only a matter of degree, however, because as the men’s forced solitude is extended by a bad storm and they resort to kerosene cocktails, things fall apart completely. They might dance together drunkenly, but madness is immediately beneath the surface, and violence eventually erupts. What a rescue crew might find upon their arrival isn’t revealed, but it certainly won’t be pretty.

Eggers, working from a script concocted by him and his brother Max, has had cinematographer Jarin Blaschke shoot the film in stark black-and-white, conjuring up images reminiscent of lustrous period photographs. But he also uses the old boxy aspect ratio that gives them the shape of a near-square, creating a constricting, claustrophobic feel but also focusing the viewer’s undivided attention on the battle of wills occurring on screen. The production design by Craig Lathrop and costumes by Linda Muir are integral to the effect, as also is the careful sound design by Damian Volpe, with the mournful warnings of the foghorn constantly interacting with the natural ambient sounds and Mark Korven’s imaginative score. Though editor Louise Ford extends the film to nearly two hours, the result is hallucinatory rather than dull.

Of course as a basically two-person piece, much of the fascination of “The Lighthouse” depends on the performances, Dafoe starts at high pitch and only increases the volume, but Pattinson begins in his usual calmer mode, gradually becoming as ferocious as his co-star. It’s an acting duel in which both men prove at the top of their game.

“The Lighthouse” is a brooding exercise in semi-Gothic gloom that threatens to slip into unintentional absurdity but never quite does. It’s a mesmerizing film that’s also pleasurably mystifying.