From 1618, Duchy of Prussia was ruled by the Electors of Brandenburg.

An excerpt from the article 24 facts about Kaliningrad

In 1657, the Duchy of Prussia became independent from the First Polish-Lithuanian Commonwealth. The elector forced the city to take an oath of allegiance, although the urban estates still recognized Königsberg as part of the Kingdom of Poland.

In 1701, the Elector of Brandenburg was crowned King of Prussia in Königsberg as Frederick I. He merged three cities: the Old Town, Knipawa, and Lipnik into one city of Königsberg, whose name from then on was: the Royal Prussian Capital and Residential City of Königsberg.