The base, at the Mina Salman Port in Bahrain, will host ships including destroyers and aircraft carriers.
The UK said it was an “expansion of the Royal Navy’s footprint” and would “reinforce stability” in the Gulf.
Bahrain will pay most of the £15m ($23m) needed to build the base, with the British paying ongoing costs.
UK Foreign Secretary Philip Hammond, who signed the deal at a security conference in Manama, Bahrain, said it was “just one example of our growing partnership with Gulf partners to tackle shared strategic and regional threats”.
He said the move “builds upon our 30-year track record of Gulf patrols” and would allow the UK and its allies in the region to “tackle the threats we face together”.
“To our partners in the Gulf my message is this: Your security concerns are our security concerns,” he told the conference.
Mr Hammond said the new base showed Britain’s commitment to a “sustained presence east of Suez” – referring to the wording of a 1968 decision to close bases east of Suez by 1971.
Labour’s shadow defence secretary Vernon Coaker said his party “supports the Royal Navy having a strong international footprint”, but said the government must “clearly set out its reasons for making this particular decision at this time.”
BBC security correspondent Frank Gardner there was already a “rotating presence” of four British minesweepers at the Mina Salman Port, but the UK had been “piggybacking” on the US naval base there.
He said the new facility would be one of the most important Royal Navy bases in the world and would be used for a “whole host of things” including supporting UK operations in Iraq, where RAF jets have been attacking targets as part of a US-led coalition against Islamic State (IS) militants.
The base would also be used for operations against piracy and for aerial surveillance, he added.
He also said the threat of IS may have made Gulf monarchies “content to invite British forces to set up on their soil”.
UK Defence Secretary Michael Fallon added: “This new base is a permanent expansion of the Royal Navy’s footprint and will enable Britain to send more and larger ships to reinforce stability in the Gulf.”
Bahrain’s foreign minister Sheikh Khalid bin Ahmed bin Mohammed Al-Khalifa said: “Bahrain looks forward to the early implementation of today’s arrangement and to continuing to work with the UK and other partners to address threats to regional security.”